您的位置:首页 > 编程语言 > Java开发

Struts2的exception配置

2013-12-09 17:11 288 查看
啊啊啊啊今天顺便把exception的配置也看了看,还有interceptor的,一会再写,exception的配置也是非常的简单的,如果是你自己写exception的话,就抛出自己的exception就行了,配置的时候首先配置好映射关系,然后把你的result的名字写好,然后根据你的result的名字,下面的result配置就可以为你的exception来一个跳转界面,很方便也很简单。这里面我就有点没写好的,就是我想让exception帮我传个参数,就是wrongname,然后弄了半天,其实我也是非常喜欢EL的,但是老报错,原来是没有加c库。汗

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"></constant> <!-- 发布的时候是要把这个false掉的 -->
<package name="struts2" extends="struts-default" >
<!-- <global-results>
<result name="error" type="redirect">
/chapter8/error.jsp
</result>
</global-results>
--> <!-- 这个和defult-action-ref不能一起用 -->

<default-action-ref name="forwardaction">apter8/error.jsp</default-action-ref>
<action name="forwardaction" class="chapter8.action.DefaultAction">
<result name="error" type="redirect">
apter8/error.jsp
</result>
</action>

<action name="login" class="chapter8.action.QueryAction" method="login">
<exception-mapping result="exception" exception="chapter8.exception.UserException"></exception-mapping>
<result name="exception">
/chapter8/exception.jsp
</result>
<result name="loginsuccess" >
/chapter8/loginsuccess.jsp
</result>
<result name="loginnotfound">
/chapter8/loginnotfound.jsp
</result>
</action>
<action name="register" class="chapter8.action.QueryAction" method="register">
<result name="registersuccess">
/chapter8/registersuccess.jsp
</result>
</action>
</package>
</struts>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'exception.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
您不能用 ${wrongname} 作为用户名!
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐