index.jsp里:<a href="dynaAction!test1">当出现异常时跳转到指定页面</a><br>
DynaAction.java里:
1 package com.xsl.action; 2 3 import java.util.Random; 4 5 import com.opensymphony.xwork2.ActionSupport; 6 7 public class DynaAction extends ActionSupport { 8 9 public String test1(){ 10 System.out.println(10/0); 11 return SUCCESS; 12 } 13 14 }
struts.xml里:
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> 3 <struts> 4 <package name="xsl" namespace="/" extends="struts-default"> 5 <!-- 全局异常的处理 --> 6 <global-results> 7 <result name="error">/error.jsp</result> 8 </global-results> 9 <global-exception-mappings> 10 <exception-mapping result="error" exception="java.lang.Exception"></exception-mapping> 11 </global-exception-mappings> 12 13 <action name="dynaAction" class="com.xsl.action.DynaAction"> 14 <result>/success.jsp</result> 15 </action> 16 </package> 17 </struts>
error.jsp里:系统出错,请稍后再试!