码迷,mamicode.com
首页 > Web开发 > 详细

struts2 Action向JSP传值方式

时间:2016-06-14 13:36:38      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

1、通过属性getXXX()和setXXX()方式

Action类

public class Test {

    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String test1(){
        
        name="zhangsan";
        return "success";    
    }
}

在JSP页面

${username}  <!-- EL表达式-->
<s:property value="username"/>  <!-- OGNL方式 -->

 

2、通过ActionContext方式

Action

public class Test {
    public String test1(){
        ActionContext.getContext().put("age", 18);
        return "success";    
    }
}

JSP页面

${age}  <!-- EL表达式-->
<s:property value="#age"/>  <!-- OGNL方式 -->

 

3、通过Sevlet API方式

Action

public class Test {
    public String test1(){
        ServletActionContext.getRequest().setAttribute("age", 18);
        return "success";    
    }
}

JSP页面

${age}  <!-- EL表达式-->
<s:property value="#request.age"/>  <!-- OGNL方式 -->

 

struts2 Action向JSP传值方式

标签:

原文地址:http://www.cnblogs.com/caoyc/p/5583455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!