tomcat8.5基础 web.xml 抛出指定异常时,转到指定的页面
2017-12-06 11:51
465 查看
礼悟:
公恒学思合行悟,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
虚怀若谷良心主,愿行无悔给最苦。读书锻炼养身心,诚劝且行且珍惜。
参考链接:http://www.cnblogs.com/avenxia/archive/2012/02/15/2353076.html
部分转载:
工程目录结构
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/d2441af4e827875e55e62695977089f6.png)
web.xml
MyJsp.jsp
NotFoundError.jsp
ForRuntimeException.jsp
访问不存在的页面
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/ad9a08920724fe51e66134b636ecfa71.png)
访问MyJsp.jsp
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/64ea1b27ce6bac0ddf5d265191bb34b1.png)
扩展
标题:web.xml配置错误页面不起作用
链接:http://blog.sina.com.cn/s/blog_4d1498f10100nmvs.html
部分转载
但怎么也跳转不了,我检查了几遍配置文件,确实没有问题,这下开始郁闷了,
就开始google了,但网上答案各异,实在是看的我眼花缭乱,最后换了个浏览器好了,
那这肯定是ie的原因了,就打开ie的选项看看是不是有什么特别设置的,恰好google的时候
一篇文章说有可能跟ie选项中的友好http错误提示有关,最后问题终于解决了,呵呵。
在IE工具->Internet选项->高级中将显示友好http错误提示的前面的勾取消,ok了。
Tomcat,优秀的开源轻量级应用服务器,值得学习。
学习资源:博文头部的参考链接 + 清净的心地。
公恒学思合行悟,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
虚怀若谷良心主,愿行无悔给最苦。读书锻炼养身心,诚劝且行且珍惜。
javaEE:7
javaSE:1.8
JSTL:1.2.2
server:tomcat 8.5
browser:Chrome/Firefox
os:windows7 x64
ide:MyEclipse 2017
javaSE:1.8
JSTL:1.2.2
server:tomcat 8.5
browser:Chrome/Firefox
os:windows7 x64
ide:MyEclipse 2017
参考链接:http://www.cnblogs.com/avenxia/archive/2012/02/15/2353076.html
部分转载:
<error-page></error-page> 用来处理错误代码或异常的页面,有三个子元素: <error-code></error-code> 指定错误代码 <exception-type></exception-type> 指定一个JAVA异常类型 <location></location> 指定在web站台内的相关资源路径 比如: <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>
工程目录结构
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/d2441af4e827875e55e62695977089f6.png)
web.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>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"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MyJsp.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% int n = (1 / 0); %> This is my JSP page. <br> </body> </html>
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"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'NotFoundError.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 访问的页面居然不存在<br /> </body> </html>
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"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'ForRuntimeException.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 请稍后访问。。。┭┮﹏┭┮<br /> </body> </html>
访问不存在的页面
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/ad9a08920724fe51e66134b636ecfa71.png)
访问MyJsp.jsp
![](https://oscdn.geek-share.com/Uploads/Images/Content/202002/07/64ea1b27ce6bac0ddf5d265191bb34b1.png)
扩展
标题:web.xml配置错误页面不起作用
链接:http://blog.sina.com.cn/s/blog_4d1498f10100nmvs.html
部分转载
但怎么也跳转不了,我检查了几遍配置文件,确实没有问题,这下开始郁闷了,
就开始google了,但网上答案各异,实在是看的我眼花缭乱,最后换了个浏览器好了,
那这肯定是ie的原因了,就打开ie的选项看看是不是有什么特别设置的,恰好google的时候
一篇文章说有可能跟ie选项中的友好http错误提示有关,最后问题终于解决了,呵呵。
在IE工具->Internet选项->高级中将显示友好http错误提示的前面的勾取消,ok了。
Tomcat,优秀的开源轻量级应用服务器,值得学习。
学习资源:博文头部的参考链接 + 清净的心地。
相关文章推荐
- JSP基础 指令page errorPage 当前页面抛出异常,转发到指定页面
- tomcat8.5基础 web.xml session 默认的时间30min
- 在tomcat的web.xml中声明异常和错误页面
- tomcat,web.xml配置异常页面跳转与拦截器问题
- web.xml 配置了 error-page 不能跳转到指定页面
- TOMCAT基础-web.xml
- JavaWeb基础 通过配置web.xml 让servlet类和tomcat共同启动
- web.xml或JSP中指定错误页面
- J2EE中在web.xml异常页面跳转
- 在web.xml中配置异常处理页面
- eclipse中基于maven构建的web项目pom.xml中指定的jar包无法发布到tomcat中
- 在web.xml中配置异常处理页面
- 启动tomcat服务时,报解析/WEB-INF/applicationContext.xml异常或找不到该文件
- web.xml定义错误或异常页面的友好界面显示
- 在web.xml中配置异常处理页面
- tomcat web.xml配置错误页面
- 错误提示web.xml定义错误或异常页面的友好界面显示
- J2EE中在web.xml异常页面跳转
- Web应用中设置了异常统一处理页面,捕捉指定异常时的处理问题
- TOMCAT-HOME/webapps/项目名/META-INF/context.xml的注释含有中文,启动报异常