struts.xml配置
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- 对默认拦截器的引入 -->
<include file="struts-default.xml" />
<package name="eticket" extends="struts-default">
<!-- 全局异常映射 -->
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception">
</exception-mapping>
</global-exception-mappings>
<action name="airTicketAction" class="AirTicketAction">
<result>airticket/airticket.jsp</result>
<result name="detail">airticket/airticketdetail.jsp</result>
<result name="order">airticket/airticketorder.jsp</result>
<result name="error">error.jsp</result>
<!-- 局部异常映射 -->
<exception-mapping result="nullPoint" exception="java.lang.NullPointerException"></exception-mapping>
<result name="nullPoint">error.jsp</result>
</action>
</package>
</struts>
error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:text name="login.title"></s:text></title>
</head>
<body>
<h1>出错了!</h1>
<s:property value="exception.message" />
<s:property value="exceptionStack" />
</body>
</html>
示例
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class Test extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO 自动生成方法存根
//产生一个除数为0的异常
int i = 1/0;
return SUCCESS;
}
}
分享到:
相关推荐
NULL 博文链接:https://wlh269.iteye.com/blog/321746
Struts2异常处理机制
NULL 博文链接:https://wjt276.iteye.com/blog/690323
配合博文:http://blog.csdn.net/u011638419/article/details/41343683
Struts简介 什么是Struts Struts基本运作流程 ActionMapping类 Action类 ActionForm类 ActionError与ActionMessage 协同开发 模块化程序 Struts异常处理 Struts国际化支持 PlugIn接口 等等
项目中出现的异常通常要用一个友好的异常页面来显示,通过对struts2.xml的配置能拦截全局异常,只要出现异常就会转向异常页面。
struts常见异常及处理
Struts映射到Model 2设计模式的完整介绍 , 详细论述利用JSP使用Struts的知识,包括Struts标记库 Struts异常处理、验证和登录 Struts应用程序的国际化和本地化 完整论述新StrutsTiles模板库 ...
从网上搜索的一段关于struts1.x自定义异常处理的方法。
struts2的异常处理,解决异步请求时,异常以json格式发送到客户端。以及dao单元测试的配置。
Struts2 异常处理的四种获取属性方法,大家可以借鉴学习
Jakarta+Struts+编程[扫描版][中文] 高效的Model 2编程并不是一项简单的任务,开发人员经常...Struts异常处理、验证和登录 Struts应用程序的国际化和本地化 完整论述新StrutsTiles模板库 Struts应用程序的打包和发布
struts2 单文件,多文件上传及异常处理
Struts映射到Model 2设计模式的完整介绍 , 详细论述利用JSP使用Struts的知识,包括Struts标记库 Struts异常处理、验证和登录 Struts应用程序的国际化和本地化 完整论述新StrutsTiles模板库 ...
NULL 博文链接:https://yuxisanren.iteye.com/blog/1707508
本文档主要介绍了struts2的异常处理机制,希望对你有所帮助。
通过定义继承RuntimeException的异常类及继承ExceptionHandler的异常处理类,手动从dao层捕获异常。非常实用!
Struts2的异常处理实例 博文链接:https://zmx.iteye.com/blog/463996
9.5 Struts异常处理 13 第10章 struts中使用国际化(i18n) 13 10.1 struts国际化程序尝试 13 10.1 Java对i18n的支持 14 10.1 struts框架中对国际化的支持 14 第11章 Validator验证框架 14 11.1 安装和配置Validator...