Struts2 OGNL表达式

 

1:Struts标签库的位置

 

 

 2:使用OGNL表达式前 需要在JSP中导入Struts2的标签库

  <%@ taglib prefix="s" uri="/struts-tags" %>


 

3:输出标签

          <S:property value = ""  />  :如果不写value输出的值 那么默认输出栈顶的值。

 

 

 

 

测试的Action

public class OGNLDemo extends ActionSupport {

    public String testOgnl(){
    
     //1:
ServletActionContext.getRequest().setAttribute(
"a","aaaaaaa"); //将值存入map的栈顶
     //2:
Person p = new Person(); p.setName("hello"); ValueStack v = ServletActionContext.getValueStack(ServletActionContext.getRequest());//将对象放入对象栈顶 v.push(p); System.out.println("Hello struts2' debug"); return "success"; } }

 

页面取值的方式:

      <s:debug></s:debug>
      1: 对象中取值: <s:property value="name"></s:property>
      2: Map栈中取值:<s:property value="#request.a"></s:property>

结果
         

 

 

4:输出标签 主要用于输出集合的例如List,Map

          <S:iterator value="" var=""  status />  :

 

 

 

特别注意表单中的value

 

 

 

 

 
















































posted @ 2020-05-29 10:47  gaoshengjun  阅读(115)  评论(0编辑  收藏  举报