zoukankan      html  css  js  c++  java
  • struts2 Action向JSP传值方式

    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方式 -->
  • 相关阅读:
    058_从键盘读取一个论坛积分,判断论坛用户等级
    057_统计 Linux 进程相关数量信息
    bzoj3436
    bzoj1202
    bzoj1044
    bzoj2338
    bzoj1854
    bzoj1856
    830C
    bzoj2132
  • 原文地址:https://www.cnblogs.com/caoyc/p/5583455.html
Copyright © 2011-2022 走看看