码迷,mamicode.com
首页 > 其他好文 > 详细

Structs2 全局异常界面,发生异常均进入此界面

时间:2016-08-23 14:54:32      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

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;
    }
}

 



Structs2 全局异常界面,发生异常均进入此界面

标签:

原文地址:http://www.cnblogs.com/w198/p/5798901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!