Struts的actionerror和actionmessage标签

一 action

package org.crazyit.app.action;

import com.opensymphony.xwork2.ActionSupport;

public class DemoAction extends ActionSupport
{
    public String execute()
    {
        //添加两条Error信息
        addActionError("第一条错误消息!");
        addActionError("第二条错误消息!");
        //添加两条普通信息
        addActionMessage("第一条普通消息!");
        addActionMessage("第二条普通消息!");
        return SUCCESS;
    }
}

二 视图

1 s-msg.jsp

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>使用s:actionerror和s:actionmessage标签生成错误提示</title>
<s:head/>
</head>
<body>
    <s:action name="demo" executeResult="true"/>
</body>
</html>

2 demo.jsp

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>使用s:actionerror标签</title>
</head>
<body>
<s:actionerror/>
<s:actionmessage />
</body>
</html>

三 配置

<?xml version="1.0" encoding="GBK"?>
<!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.i18n.encoding" value="GBK"/>

    <package name="lee" extends="struts-default">
        <!-- 定义一个简单的Action -->
        <action name="demo" class="org.crazyit.app.action.DemoAction">
            <result>/WEB-INF/content/demo.jsp</result>
        </action>

        <action name="*">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>

四 测试

Struts的actionerror和actionmessage标签

上一篇:Struts----类型转换


下一篇:java – c:当不为空/空检查时