分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

tomcat8.5基础 web.xml 抛出指定异常时,转到指定的页面

发布时间:2023-09-06 01:29责任编辑:傅花花关键词:xmltomcat

礼悟:
     好好学习合思考,尊师重道存感恩。叶见寻根三返一,江河湖海同一体。
          虚怀若谷良心主,愿行无悔给最苦。读书锻炼强身心,诚劝且行且珍惜。




       javaEE:7           
       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>

工程目录结构

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>

访问不存在的页面

访问MyJsp.jsp

扩展

  标题:web.xml配置错误页面不起作用

  链接:http://blog.sina.com.cn/s/blog_4d1498f10100nmvs.html

  部分转载  

    但怎么也跳转不了,我检查了几遍配置文件,确实没有问题,这下开始郁闷了,

    就开始google了,但网上答案各异,实在是看的我眼花缭乱,最后换了个浏览器好了,

    那这肯定是ie的原因了,就打开ie的选项看看是不是有什么特别设置的,恰好google的时候

    一篇文章说有可能跟ie选项中的友好http错误提示有关,最后问题终于解决了,呵呵。

    在IE工具->Internet选项->高级中将显示友好http错误提示的前面的勾取消,ok了。


java优秀,值得学习。
学习资源:博文头部的参考链接 + 清净的心地。

tomcat8.5基础 web.xml 抛出指定异常时,转到指定的页面

原文地址:http://www.cnblogs.com/jizuiku/p/7991963.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved