Configuring a custom 404 error page in tomcat

Source: Internet
Author: User



404,50x Such errors are often encountered.



If the%catalina_home%\conf\web.xml and the specific application have the settings%catalina_home%\webapps\root\web-inf\web.xml



The application is in effect.






How to set up a friendly user experience, for example in the Windows environment:



Add the default file when an exception occurs, the file location is as follows (if you do not set reloadable to True or autodeploy= "true", you will need to restart Tomcat for the changed web. XML to take effect):







(1) Add in Web-app node of%catalina_home%\conf\web.xml


    < Error-page > < Error-code >404</error-code>  < location >/notfilefound.jsp</location> <!--defined pages must start with "/"-- </ Error-page >






Effect Show:
Normal Condition:






Scene when 404 is present:

%catalina_home%\webapps\root\notfilefound.jsp






(2) The contents of the same format are added in the Web-app node of the%catalina_home%\webapps\root\web-inf\web.xml and (1).
For demonstration purposes, 404.html is used here












Look at the effect when it doesn't exist:



 The browser has a masking effect on the 404 configuration of Tomcat:












If you want to make the report 404 direct jump, you can add a jump in the 404.html action will be:


<HTML> <Head> <Metahttp-equiv= "Content-language"content= "ZH-CN"> <Metahttp-equiv= "Content-type"CONTENT= "text/html; charset=gb2312">  <Meta  http-equiv= "Refresh"  content= "0.1;url=http:// Www.cnblogs.com "> <title></title> </Head> <Body> </Body> </HTML> 





3. Not only can you go to the page based on the HTML error code, but you can also jump by exception type, for example:


<error-page>  
    <exception-type>javax.servlet.ServletException</exception-type>  
    <location>/errorhandler.jsp</location>  
</error-page>  


Not only can you use the JSP built-in exception object to get the exception, you can also get the attribute in request. For example:


<% @page contenttype= "Text/html;charset=big5" iserrorpage= "true"%>  


Http://www.cnblogs.com/yjhrem/articles/2206878.html






Configuring a custom 404 error page in tomcat


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.