随笔 - 0, 文章 - 264, 评论 - 170, 引用 - 0

导航

<2016年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

留言簿(6)

随笔分类

文章分类

文章档案

AI

android+移动开发

apache等开源类包,工具相关

cdn

concurrent

C语言

git、svn等工具使用

groovy、grails

Hadoop、Storm、Spark大数据相关

hibernate、JPA等持久化技术

html,dom,js,css、ext、mui等前端、移动前端相关

HTTP、HTTPS、TCP、UDP等协议相关

IM、openfire

Java基础

java性能优化

jquery

linux相关

lucene、solr等搜索技术相关

maven gradle ant Jenkins自动化构建与持续集成

memcache

mongodb

nginx、squid、haproxy、varnish

OLAP

python、shell、perl、php

redis

rmi相关

spring

struts、webwork

tcp/ip

tomcat,jsp,servlet相关

velocity等实用工具相关

业务相关

互联网安全、过滤、网络

修炼

其他

区块链

压力、性能测试相关

地图相关

基础

多线程

开发工具相关

数据库

架构

移动互联网

设计模式

搜索

  •  

最新评论

web工程中自定义异常处理页面

在JAVA WEB工程中可以自定义异常处理页面。
具体操作步骤如下:
1、在web.xml中,加上如下配置:
<error-page>
    
<error-code>500</error-code>
    
<location>/error/500.jsp</location>
</
error-page>

2、新建500.jsp,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/xml; charset=UTF-8" %>
<wml>
<%=request.getAttribute("javax.servlet.error.message")%>
</wml>
注意,此页面跟JSP的异常页面不是一个意思,可以没有isErrorPage="true"这个头属性。同时也不需要设置:response.setStatus(HttpServletResponse.SC_OK);
同时:request.getAttribute("javax.servlet.error.message")方法,获取抛出的异常信息。注意,在这不能通过exception.getMessage()获取。
异常的其他属性还有:javax.servlet.error.status_codejavax.servlet.error.exception_type。要获取全部的属性,请用request.getAttributeNames()遍历,查看。

3、测试,在测试代码中写上:response.sendError(500,"ImgUrl config must not by empty!");
经测试,结果返回如下:
vmagid must not empty!

posted on 2010-12-17 17:25 小一败涂地 阅读(2262) 评论(1)  编辑  收藏 所属分类: jsp,servlet相关

评论

# re: web工程中自定义异常处理页面  回复  更多评论   

ADSF
2016-07-18 16:18 | 的A

只有注册用户登录后才能发表评论。


网站导航: