标签:
struts.xml 其中个界面的name 均可随机应变
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 动态调用 --> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!-- 开发者模式 --> <constant name="struts.devMode" value="true" /> <!-- 默认包 --> <package name="default" namespace="/" extends="struts-default"> <!-- 全局界面 --> <global-results> <result name="error">/message.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="error" exception="java.lang.Exception"/> </global-exception-mappings> <action name="user*" class="com.edusk.action.UserAction" method="{1}"> <result>/ok.jsp</result> </action> </package> <!-- 包可以继承其他包 此包为使用默认包的全局错误界面--> <package name="stu" namespace="/stu" extends="default"> <action name="stu*" class="com.edusk.action.StuAction" method="{1}"> <result>/ok.jsp</result> </action> </package> </struts>
message.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> 发生异常,${message },进入了异常消息界面! </body> </html>
ok.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> 正常来的界面! </body> </html>
StuAction.java
package com.edusk.action; import com.opensymphony.xwork2.ActionSupport; public class StuAction extends ActionSupport { private static final long serialVersionUID = 1L; public String login() { int a = 1/0; return SUCCESS; } }
UserAction.java
package com.edusk.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private static final long serialVersionUID = 1L; public String login() { int a = 1/0; return SUCCESS; } }
标签:
原文地址:http://www.cnblogs.com/w198/p/5798901.html