I have web-apps deployed on my server, lets call them ABC and XYZ. I want to show a custom error page page when I try to access an unknown web-app. For example if I try to access localhost/asdfasd it should display my custome error page.
I have tried adding something like below in conf/web.xml, but it doesn't work I still see the default Tomcat 404 error page.
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
But the error-page works when I use it in web.xml of each web-app. So when I try access localhost/ABC/non_existing_page I see my custom error page.
Related
With wicket is is possible to set 500 in to ways:
In WicketApplication class like that
getApplicationSettings().setInternalErrorPage(MyError500.class);
Via "classical" way in web.xml:
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
Note that in case of web.xml url /404 is mapped to same Error page.
Could someone provide me a difference? Is it enough to use just web.xml with page url mapping or it is neccessary to use both files?
404 is when your user hits an url for which there is no page/resource/servlet.
Internal error page is 500.
Wicket will prefer its application setting. Depending on another setting (org.apache.wicket.settings.ExceptionSettings#getUnexpectedExceptionDisplay()) Wicket could be configured to use /500 from web.xml.
Any other non-Wicket Servlet/Filter in this application may have its own logic or fallback to /500.
I have multiple webapps deployed on tomcat. I have configured error page in $CATALINA_BASE/conf/web.xml :
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>
My requirement is to create only one error.jsp page that can be accessed by all the webapps. But when I create an error.jsp page and put it in $CATALINA_BASE/error.jsp location, my webapps are not able to access it when an exception occurs say ArithmeticException. It redirects to a blank page instead.
The only way I could access the error page is by creating an individual error page for each application and put it in respective WEB_INF folder. But I want only one error.jsp file that can be shared by multiple webapps. Is it possible?
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!
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 .
I am using Jboss server, i want to know does it recognize all the HTTP Client Error Code(4XX) and HTTP Server Error Code(5XX) so that i can configure my custom error page like for 502, 503 etc. in web.xml? Thanks in advance.
Edit: i did't find any documentation that has defined this. but #Jeremy suggested me a way to test it out:
Write a Servlet to return error code you want as following.
response.sendError([Error code goes here],
"Error Message");
I think you are looking for this:
<error-page>
<error-code>404</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
To test this, write a servlet that specifically returns the error code.
There are few approaches to set custom error pages.
If you are using JSP's in presentation layer.
foo.jsp
<%# page errorPage="/errorPage.jsp" %> // Here we are redirecting to error.jsp if any exception is thrown
errorPage.jsp
<%# page isErrorPage="true" %>
I suggest this for development purposes.
At Application Level
Setting errorpages in web.xml
like above answer
<error-page>
<error-code>404</error-code>
<location>/ErrorPage.jsp</location>
</error-page>
I still need to experiment with Container level, by editing web.xml found in jboss-web.sar or jboss-tomcatxx.sar