tomcat8.5 base web. XML when throwing a specified exception, go to the specified page

Source: Internet
Author: User

Li Wu:
Good study and thinking, honouring teachers save Thanksgiving. Leaf See root three return to one, rivers the same oneness.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.



Javaee:7
javase:1.8
jstl:1.2.2
Server:tomcat 8.5
Browser:chrome/firefox
Os:windows7 x64
Ide:myeclipse



Reference Link: http://www.cnblogs.com/avenxia/archive/2012/02/15/2353076.html

Partial reprint:

    <error-page></error-page> a page that handles error codes or exceptions with three child elements:    <error-code></error-code> Specify error codes    <exception-type></exception-type> Specify a Java exception type    <location></location> Specify the associated resource path within the Web site such as:<error-page>    <error-code>404</error-code>    <location>/ Error404.jsp</location></error-page><error-page>    <exception-type> Java.lang.exception</exception-type>    <location>/exception.jsp</location></error-page >

Project directory Structure

Xml

  

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "> <display-name>day12</ display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file& Gt;index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file> Default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file> default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>verifycodeservlet </servlet-name> <servlet-class>com.jizuiku.servlet.VerifyCodeServlet</servlet-class> </ servlet> <servlet-mapping> <servlet-name>VerifyCodeServlet</servlet-name> <url-pattern>/verifycodeservlet</url-pattern> </servlet-mapping> <error-page> < Exception-type>java.lang.arithmeticexception</exception-type> <location>/error/ forruntimeexception.jsp</location> </error-page> <error-page> <error-code>404</ error-code> <location>/error/NotFoundError.jsp</location> </error-page> </web-app>

myjsp.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

notfounderror.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

forruntimeexception.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

Accessing pages that do not exist

Visit myjsp.jsp

Extended

Title: Web. XML Configuration error page does not work

Links: http://blog.sina.com.cn/s/blog_4d1498f10100nmvs.html

Partial reprint

But how also can't jump, I checked a few times configuration file, really no problem, this started depressed,

Started Google, but the answer is different on the web, it is to see my dazzling, finally changed a browser good,

That this must be the reason for IE, open IE's options to see if there is anything special set, exactly Google time

An article said it is possible with the IE option in the friendly HTTP error hint about, finally solved the problem, hehe.

The front tick of the friendly HTTP error prompt will be displayed in advanced ,Internet Options , ie tools , OK.

Java is good, worth learning.
Learning resources: The reference link to the head of the blog + Pure Heart.

tomcat8.5 base web. XML when throwing a specified exception, go to the specified page

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.