`
孤星119
  • 浏览: 122673 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Web Project errorpage设置

 
阅读更多

方法:
1.web.xml中添加 如下代码

	  <!-- 400错误 请求无效 -->
    <error-page>
        <error-code>400</error-code>
        <location>/error.jsp</location>
    </error-page>
    <!-- 404 页面不存在错误 -->
    <error-page>
        <error-code>404</error-code>
        <location>/error.jsp</location>
    </error-page>
   <!-- 500 服务器内部错误 -->
    <error-page>
        <error-code>500</error-code>
        <location>/error.jsp</location>
    </error-page>
    <!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/error.jsp</location>
    </error-page>
    <!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
    <error-page>
        <exception-type>java.lang.NullPointerException</exception-type>
        <location>/error.jsp</location>
    </error-page>
    <error-page>
        <exception-type>javax.servlet.ServletException</exception-type>
        <location>/error.jsp</location>
    </error-page>

 

 

2.error.jsp代码

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page	language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>JSP Page</title>
</head>
<body>
	页面异常<br>
	请联系管理员
</body>
</html>

 

 

3.测试页面 errorPageTest.jsp

   这里故意设置 1/0 为了测试

 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=GB18030"> 
<title>testErrorPage</title> 
</head> 
<body> 
<% 
	int i=1/0;
%> 
</body> 
</html> 

 

 

4.测试

     1).访问测试页面 转到error.jsp 则证明成功
     2).浏览器地址栏中输入项目中一个不存在的页面 转到error.jsp 则证明成功

5.其它

  若不在web.xml配置错误页面,
  则需要在error.jsp中指定

  <%@page isErrorPage="true"%>

 

  且需要有可能出错的页面 设置 

<%@page errorPage="error.jsp" %>

 

 

  
 6.注意:
  有时候error.jsp页面无效 可能是浏览器设置造成的 
  解决方案:
  1).在IE【工具】->【Internet选项】->【高级】中勾掉【显示友好http错误提示】;
  2).确保error.jsp的大小>1024字节。

分享到:
评论

相关推荐

    WEB17Project-jsp.rar 源代码

    完成商品的列表的展示。 3.jsp指令(3个) jsp的指令是指导jsp翻译和运行的命令,jsp包括三大指令: 1)page指令 --- 属性...errorPage:当当前页面出错后跳转到哪个页面 isErrorPage:当前页面是一个处理错误的页面

    JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part2

    3.3.5 errorhandler接口 73 3.3.6 使用sax解析xml文档实例 74 3.4 jdom 83 3.4.1 下载并配置jdom 83 3.4.2 jdom api介绍 84 3.5 dom4j 88 3.5.1 下载并配置dom4j 88 3.5.2 dom4j api介绍 88 3.5.3 第一个...

    JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part3

    3.3.5 errorhandler接口 73 3.3.6 使用sax解析xml文档实例 74 3.4 jdom 83 3.4.1 下载并配置jdom 83 3.4.2 jdom api介绍 84 3.5 dom4j 88 3.5.1 下载并配置dom4j 88 3.5.2 dom4j api介绍 88 3.5.3 第一个...

    JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part4

    3.3.5 errorhandler接口 73 3.3.6 使用sax解析xml文档实例 74 3.4 jdom 83 3.4.1 下载并配置jdom 83 3.4.2 jdom api介绍 84 3.5 dom4j 88 3.5.1 下载并配置dom4j 88 3.5.2 dom4j api介绍 88 3.5.3 第一个...

    JAVA WEB 开发详解:XML+XSLT+SERVLET+JSP 深入剖析与实例应用.part5

    3.3.5 errorhandler接口 73 3.3.6 使用sax解析xml文档实例 74 3.4 jdom 83 3.4.1 下载并配置jdom 83 3.4.2 jdom api介绍 84 3.5 dom4j 88 3.5.1 下载并配置dom4j 88 3.5.2 dom4j api介绍 88 3.5.3 第一个...

    webservice-ajax

    ... &lt;/system.web&gt; ... &lt;configuration&gt; Making client-side JavaScript code Let us take a look at the default.aspx file that was automatically created in our project (if it was not - ...

    CSharp 3.0 With the .NET Framework 3.5 Unleashed(english)

    11 Error and Exception Handling 260 Why Exception Handling? 261 Exception Handler Syntax: The Basic try/catch Block 261 Ensuring Resource Cleanup with finally Blocks 263 Handling Exceptions ...

    Professional C# 3rd Edition

    The ASP.NET Web Matrix Project 335 WinCV 335 Summary 337 Chapter 13: Assemblies 339 What Are Assemblies? 339 The Answer to DLL Hell 340 Features of Assemblies 341 Application Domains and Assemblies ...

    UiPath高级开发者认证-操作题

    Scrape the data in all the pages of the table, page by page, ensuring error handling and recovery. 3. For each page: - Filter the records where Status is 'Open'; - Filter the records where Type ...

    ICS delphixe10源码版

    .\Install Component packages project groups for all versions .\Packages (was Delphi\Vc32) Delphi (7 and up) and C++Builder (2006 and up) packages projects .\Source (was Delphi\Vc32) ICS Delphi source ...

    VB.NET Developer's Guide(4574).pdf

    Error Handling 210 Summary 213 Solutions Fast Track 214 Frequently Asked Questions 217 NOTE When porting Visual Basic applications to Visual Basic .NET, be careful of the lower bounds of arrays. If...

    Beginning Microsoft Visual CSharp 2008 Wiley Publishing(english)

    Creating a Simple Page 666 Server Controls 673 Event Handlers 674 Input Validation 679 State Management 683 Authentication and Authorization 689 Reading and Writing to an SQL ...

    word自动转化为chm

    Please note: Do not save it as “Single File Web Page” or “Web Page, Filtered”. Then you can open the saved “Web File” by click the “Browse” button next to the “Source Word File” textbox in...

    外文翻译 stus MVC

    Struts can help you control change in your Web project and promote specialization. Even if you never implement a system with Struts, you may get some ideas for your future servlets and JSP page ...

    nServer-v2.1023[FTP + MYSQL + HTTP + PHP(FCGI)]

    - Nginx添加31.server_error_page配置,用于单独自定义错误提示 2011年10月3日 - 重写“检测网络、运行权限”代码 2011年9月29日 - 优化config.php脚本,支持自定义IP、临时目录、网站目录 - 修正zend路径为linux...

    spring-boot-reference.pdf

    Welcome Page 27.1.7. Custom Favicon 27.1.8. Path Matching and Content Negotiation 27.1.9. ConfigurableWebBindingInitializer 27.1.10. Template Engines 27.1.11. Error Handling Custom Error Pages ...

    Beginning Python (2005).pdf

    Chapter 21: Web Applications and Web Services 459 REST: The Architecture of the Web 460 Characteristics of REST 460 A Distributed Network of Interlinked Documents 461 A Client-Server Architecture ...

    Django 1.0 Website Development.pdf

    Setting error pages 238 Summary 239 Chapter 12: What Next? 241 Custom template tags and filters 242 Model managers and custom SQL 243 Generic views 244 Contributed sub-frameworks 245 Flatpages ...

    EurekaLog_7.5.0.0_Enterprise

    6)....Fixed: Wrong code page was used to decode ANSI bug reports 7)....Fixed: Attaching .PAS files instead of .OBJ in C++ Builder 2006+ Pro/Trial EurekaLog 7.2 Hotfix 1 (7.2.1.0), 3-April-2015 1).......

    Django 1.1 Testing and Debugging.pdf

    The twill web browsing and testing tool 153 Using the twill command line program 155 Using twill in a TestCase 159 Summary 167 Chapter 6: Django Debugging Overview 169 Django debug settings 170 ...

Global site tag (gtag.js) - Google Analytics