想飞就别怕摔

大爷的并TM骂人

struts2学习笔记(五)--result返回值的其他用法

result可以动态的返回。方便了struts2的使用,不过这种方法很少使用。
第一种result返回值方法
struts.xml中的配置如下:
<struts>
    
<constant name="struts.devMode" value="true" />
    
<package name="user" namespace="/user" extends="struts-default">
        
        
<action name="user" class="com.bjsxt.struts2.user.action.UserAction">
            
<result>${r}</result>
        
</action>        
    
</package>
        
</struts>
action的写法:
public class UserAction extends ActionSupport {
    
private int type;
    
    
private String r;

    
public String getR() {
        
return r;
    }

    
public void setR(String r) {
        
this.r = r;
    }

    
public int getType() {
        
return type;
    }

    
public void setType(int type) {
        
this.type = type;
    }

    @Override
    
public String execute() throws Exception {
        
if(type == 1) r="/user_success.jsp";
        
else if (type == 2) r="/user_error.jsp";
        
return "success";
    }

}

第二种result返回值方法
struts.xml中的配置如下,这种方法可以把type值传递到页面中去。在页面中可以渠道type的值,<s:property value="#parameters.t">
<struts>
    
<constant name="struts.devMode" value="true" />
    
<package name="user" namespace="/user" extends="struts-default">
        
        
<action name="user" class="com.bjsxt.struts2.user.action.UserAction">
            
<result type="redirect">/user_success.jsp?t=${type}</result>
        
</action>        
    
</package>
        
</struts>
action的写法:

public class UserAction extends ActionSupport {
    
private int type;
    
    
public int getType() {
        
return type;
    }

    
public void setType(int type) {
        
this.type = type;
    }

    @Override
    
public String execute() throws Exception {
        
return "success";
    }

}

posted on 2011-12-11 13:23 生命的绽放 阅读(2137) 评论(1)  编辑  收藏 所属分类: Struts2.0

评论

# re: struts2学习笔记(五)--result返回值的其他用法[未登录] 2013-12-29 15:59 A

A  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2011年12月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(5)

随笔分类(94)

随笔档案(93)

文章分类(5)

文章档案(5)

相册

JAVA之桥

SQL之音

兄弟之窗

常用工具下载

积分与排名

最新评论

阅读排行榜