首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

strust2 错误处理

2012-08-31 
strust2 异常处理Action代码package exceptionimport com.opensymphony.xwork2.ActionSupportpublic cla

strust2 异常处理
Action代码

package exception;import com.opensymphony.xwork2.ActionSupport;public class ExTestAction extends ActionSupport {private static final long serialVersionUID = 1L;public String test() throws Exception {throw new Exception("抛出异常");}}
struts.xml 配置
<struts><constant name="struts.enable.DynamicMethodInvocation" value="false" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default"><global-results><result name="error">/index.jsp</result></global-results><global-exception-mappings><exception-mapping result="error" exception="java.lang.Exception"></exception-mapping></global-exception-mappings><action name="exception" method="test"><result>/index.jsp</result></action></package></struts>


jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"  %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>统一异常处理页面</title>  </head>  <body>    <s:property value="exception.message"/>  </body></html>



使用浏览器 访问 http://localhost:8080/... /exception (测试Action)

Spring MVC异常处理http://lrysir.iteye.com/admin/blogs/1054214

热点排行