Wicket mount a 404 error page - java

Is there way to mount a 404 error page in Wicket-1.5.x without adding:
<error-page>
<error-code>404</error-code>
<location>/NotFound</location>
</error-page>
to my web.xml file?
I have several applications that all use the same/similar Look/Feel. I've extracted out a lot of the common functionality including my error pages to some shared jar files. I'm already mounting a lot of common pages (Login Pages, Error Pages, etc) via an Iinitializer. Is there a way I can do the same for 404 errors?
UPDATE:
In Doing more research I also found this question:
Can I redirect to a valid Wicket page when attempting to access a non-existent page?
Which also seems to state that editing web.xml is the solution.
As I said I have several applications while editing the file isn't hard and there isn't that many, it's one more thing I'll have to remember next time I upgrade them.
If it makes a difference I'm using Tomcat-6.x Is there possibly a way to fake the <error-page> configuration setting in my web.xml by modifying ServletContext?

As far as I know you need those lines in your web.xml, but once you've done that you can still mount your common page along with everything else in your IInitializer:
application.mount(
new QueryStringUrlCodingStrategy("NotFound", NotFoundErrorPage.class));

Related

Tomcat error page issue

I have configured my tomcat6 web.xml to show my custom error page by adding these lines, described here
<error-page>
<error-code>500</error-code>
<location>/web_server_error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/web_server_error.html</location>
</error-page>
Also I came to know for each application deployed I need to put the same configuration as I did for ROOT, which is fine.
My issue is I have a simple folder webapps/docs. If I try to access any file existing in this folder say /docs/mypage.html, I can access it perfectly but if the file or directory doesn't exist in the folder like docs/faq/ I need the same error page but tomcat is showing its 404 error page.
Actually I need it because my client mention this in a vulnerability list, i.e. in this scenario the attacker can get aware of the file structure so we need to show one page on all errors.
I need to know as it is a simple folder instead of any application how to handle this issue or is it simple impossible?
Any help is highly appreciated.
This is not possible in Tomcat 6. Servlet 3.0 specifies global error pages but Tomcat 6 implements Servlet 2.5.
But it's possible to "workaround" by writing a ErrorReportValve class and register it. But beware: This is Tomcat specific!
The folder is not a web application.so your configure does not work!

How to put jsp in ROOT folder of tomcat so that the jsp is picked by all web apps

I have multiple web applications defined in my tomcat. In case of any exception, I want to throw one jsp (done using SimpleMappingExceptionResolver tag of spring). When I put the jsps in the web-inf folder of the web applications, it works fine which is obvious.
But I want to put this jsp at a common place in tomcat such as ROOT library. But if I do this, tomcat is not able to find my jsp. Can somebody tell me if any changes in web.xml is required to make this happen or I should put this jsp somewhere else.
Thanks in advance.
What do you mean by 'picked up' or 'access'? You can put a jsp file on the tomcat ROOT application, and do a 302 redirect into it everytime you encounter exception.
For example place you all-apps generic exception page on webapps/ROOT/generic_exception.jsp, then on each of your apps, add this to the web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/myapp_error.jsp</location>
</error-page>
That should redirect request into myapp_error.jsp (inside myapp) if any uncaught exception surfaces. Then inside myapp_error.jsp, just perform html meta redirect to /generic_exception.jsp
However the drawback of this approach is you are redirected into different web-app, it's difficult / require extra work if you want to pass session attributes

How to specify html page globally in Jboss?

We have a filter that redirects user to error.html, if the user is not authorized. Right now, we are keeping error.html page inside the WAR, but is there any way to make the html file public so that every war file can access this error page? It would be still better, if we make this html page as a jar and keep it in server/default/lib.
Here is the sample that is used in filter.
`reqDespacher = request.getRequestDispatcher("error.html")`
and the accessing url is
http://localhost/Context_root/error.html
Any help would be appreciated.
In JBoss5 or JBoss6, you can copy and then define this custom error.html inside the /deployer/jbossweb.deployer/web.xml of the server instance that you are running. This will require a reboot of the JBoss instance. Example for error code 404:
<error-page>
<error-code>404</error-code>
<location><relative_path_to_error_html_file_under_jbossweb.deployer_folder></location>
</error-page>
Secondly, instead of re-directing request by specifying a page manually like you are doing currently, you should use the <error-page> and <error-code> deployment directive to define custom error pages. See specify-the-default-error-page-in-web-xml-in-servlet for a detailed example on how to add error-code directives on web.xml.
For JBoss AS7 global error page configuration take a look at how-to-customize-jboss-as7-404-page .

Custom error pages in JBoss 5.0 EAP web applications

I'm deploying a web application and I want to have a default 404 page applicable to all my web applications unless stated otherwise in each application web.xml
I've accomplished something changing "jboss-as\server\myapp\deployers\jbossweb.deployer\web.xml" and adding the following
<error-page>
<error-code>404</error-code>
<location>/error404.html</location>
</error-page>
Then all 404 errors I get are redirected to /error404.html without changing each application's web.xml as I wanted.
Anyway the bizarre thing is that each war I'm deploying must have a error404.html copy because it's looking for it in its own context. I tried putting error pages in jboss-as\server\myapp\deploy\ROOT.war and they work for non-defined URLs but not for already defined applications.
Can I have only one copy of my error pages for ALL contexts and that page defined only in one web.xml?
Thanks a lot in advance.
Rafa,
is "myapp" a custom profile you created? If not then try changing the file /jboss/server/all/deployers/jbossweb.deployer/web.xml.
Where "all" is one of the available jboss profiles (all, default, standard, ...).

Remove Foobar.xhtml from URL with JSF

I have written a facelets web application using tomcat as a application server. My program has a foobar.xhtml and the URL to it is:
http://localhost:8080/Myapplication/foobar.faces
Can I change something in my application so that a link to:
http://localhost:8080/Myapplication/
..will actually render my application on http://localhost:8080/Myapplication/foobar.faces ?
Alternatively, could the http://localhost:8080/Myapplication/ be redirected to http://localhost:8080/Myapplication/foobar.faces ?
You would normally use the <welcome-file> entry in the web.xml for this. But unfortunately this doesn't work as expected on at least Tomcat when using fictive URL's which are to be passed through a servlet like a FacesServlet. Tomcat will scan for the physical file on the disk matching the exact name before forwarding. If it isn't present, then you will just face a default 404 error page.
Using /foobar.xhtml as <welcome-file> is also not going to work since that page requires to be parsed by the FacesServlet to get all the JSF stuff to work.
One of the ways to fix this is to place another real /foobar.faces file there next to the real /foobar.xhtml file. It doesn't need to be filled with code, it can be left empty. Just the presence of the physical file is enough for Tomcat to open the desired page as welcome page.
web.xml has a
<welcome-file-list>
<welcome-file>foobar.faces</welcome-file>
</welcome-file-list>
element where you can define the page to be opened.

Categories