struts中异常的处理
首先建一个异常类:
package blog;
public class MyException extends Exception {
private static final long serialVersionUID = 421319254124592915L;
public MyException(String message){
super(message);
}
}
再建一个ApplicationResources.properties文件:
invaliduser=it is a invalid user
在struts-config.xml中的actionmapping节点的action节点中加入exception节点:
<exception type="it.cast.MyException" key="invaliduser" path="/Error.jsp"></exception>
在struts-config.xml中加入message-resource节点:
<message-resources parameter="blog.ApplicationResources" key="myKey"></message-resources>
Error.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
</head>
<body>
an exception occured!
<html:errors/>
</body>
</html>
转载于:https://www.cnblogs.com/xzf007/archive/2012/07/17/2873898.html