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

struts中异常的处理

2012-07-17 20:21 288 查看












首先建一个异常类:

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>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: