最近使用struts2 做项目时, 如果在后台可以使用两种方式把属性值,存入request作用域中.

  

    第一种方式.

ActionContext.getContext().put(
                    "msgInfo","把放入数据到request作用域中..");

 

   

    第二种方式:

   还有一种方式在Action中 添加一个属性 比如:

private String info;

public Strint getInfo(){
          return info;
}

public String setInfo(String info){
          this.info = info;
}

 

 

如果使用第一种方式.在struts2标记中则需要用#request.info可以获取数据.

 

如果使用第二种方式,在struts2标记中则不需要使用”#“ 直接使用 info即可..

比如:

<s:if test="info!=null">
        能获取到request作用域的值;
</s:if>
<s:else>
       不能获取到request作用域的值;
</s:else>

输出:  能获取到request作用域的值;