struts2_07_result type(结果类型)


这里写图片描述

UserAction .java

public class UserAction extends ActionSupport{
    private Map<String,Object> request;
    private Map<String,Object> session;
    private Map<String,Object> application;

    public UserAction() {
        request= (Map) ActionContext.getContext().get("request");
        session= (Map) ActionContext.getContext().getSession();
        application= (Map) ActionContext.getContext().getApplication();
    }

    public String add(){
        request.put("request1", "request12_add");
        session.put("session1", "session12_add");
        application.put("application1", "application12_add");
        return "add";
    }

    public String del(){
        request.put("request1", "request12_del");
        session.put("session1", "session12_del");
        application.put("application1", "application12_del");
        return "del";
    }

    public String error(){
        request.put("request1", "request12_error");
        session.put("session1", "session12_error");
        application.put("application1", "application12_error");
        return "error";
    }

    public String update(){
        request.put("request1", "request12_update");
        session.put("session1", "session12_update");
        application.put("application1", "application12_update");
        return "update";
    }
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.devMode" value="true" /><!-- 开发模式,修改xml文件后不需要重启tomcat,立即生效 -->

    <constant name="struts.i18n.encoding" value="utf-8" />
    <package name="user" namespace="/user" extends="struts-default">
        <action name="useradd" class="com.test.user.UserAction" method="add">
            <!-- result的type属性默认是dispatcher 默认结果类型,用来呈现JSP页面-->
            <result type="dispatcher" name="add">/useradd.jsp</result>
        </action>
        <action name="userdel" class="com.test.user.UserAction" method="del">
            <!-- redirect将用户重定向到一个已配置好的URL-->
            <result type="redirect" name="del">/userdel.jsp</result>
        </action>

        <action name="usererror" class="com.test.user.UserAction" method="error">
            <!-- chain将action和另外一个action链接起来,这里链接到useradd的action-->
            <result type="chain" name="error">useradd</result>
        </action>

        <action name="userupdate" class="com.test.user.UserAction" method="update">
            <!-- redirectAction将用户重定向到一个已定义好的action,这里链接到userdel的action-->
            <result type="redirectAction" name="update">userdel</result>
        </action>
    </package>
</struts>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值