struts2系列十六之复杂的ognl(即<s:pro…..>)变量,类,静态变量,list,map,set

来源:互联网 发布:太阳系3d软件 编辑:程序博客网 时间:2024/06/03 02:09

    <constantname="struts.enable.DynamicMethodInvocation"value="false"/>

    <constantname="struts.devMode"value="true"/>

    <constantname="struts.ognl.allowStaticMethodAccess"value="true"></constant>

   <includefile="/com/bjsxt/struts2/ognl/ognl.xml"/>

 

Jsp页面:

<?xmlversion="1.0"encoding="GB18030"?>

<%@ page language="java"contentType="text/html; charset=GB18030"

    pageEncoding="GB18030"%>

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

<!DOCTYPEhtml PUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type"content="text/html; charset=GB18030"/>

<title>OGNL表达式语言学习</title>

</head>

<body>

   <ol>

      <li>访问值栈中的action的普通属性:username = <s:propertyvalue="username"/></li>

      <li>访问值栈中对象的普通属性(get set方法):<s:propertyvalue="user.age"/> |<s:property value="user['age']"/> |<s:property value="user[\"age\"]"/> | wrong:<%--<s:propertyvalue="user[age]"/>--%></li>

      <li>访问值栈中对象的普通属性(get set方法):<s:property value="cat.friend.name"/></li>

      <li>访问值栈中对象的普通方法:<s:propertyvalue="password.length()"/></li>

      <li>访问值栈中对象的普通方法:<s:propertyvalue="cat.miaomiao()"/></li>

      [这个奇特]<li>访问值栈中action的普通方法:<s:propertyvalue="m()"/></li>

      <hr/>

      <[这个奇特]li>访问静态方法:<s:propertyvalue="@com.bjsxt.struts2.ognl.S@s()"/></li>

      [这个奇特]<li>访问静态属性:<s:propertyvalue="@com.bjsxt.struts2.ognl.S@STR"/></li>

      [这个不懂]<li>访问Math类的静态方法:<s:propertyvalue="@@max(2,3)"/></li>

      <hr/>

      [这个奇特]<li>访问普通类的构造方法:<s:propertyvalue="newcom.bjsxt.struts2.ognl.User(8)"/></li>

      <hr/>

      <li>访问List:<s:propertyvalue="users"/></li>

      <li>访问List中某个元素:<s:propertyvalue="users[1]"/></li>

      <li>访问List中元素某个属性的集合:<s:propertyvalue="users.{age}"/></li>

      <li>访问List中元素某个属性的集合中的特定值:<s:propertyvalue="users.{age}[0]"/> |<s:property value="users[0].age"/></li>

      <li>访问Set:<s:propertyvalue="dogs"/></li>

      <li>访问Set中某个元素:<s:propertyvalue="dogs[1]"/></li>

      <li>访问Map:<s:propertyvalue="dogMap"/></li>

      <li>访问Map中某个元素:<s:propertyvalue="dogMap.dog101"/> |<s:property value="dogMap['dog101']"/> |<s:property value="dogMap[\"dog101\"]"/></li>

      <li>访问Map中所有的key:<s:propertyvalue="dogMap.keys"/></li>

      <li>访问Map中所有的value:<s:propertyvalue="dogMap.values"/></li>

      <li>访问容器的大小:<s:propertyvalue="dogMap.size()"/> |<s:property value="users.size"/></li>

      <hr/>

      [这个不懂]<li>投影(过滤):<s:propertyvalue="users.{?#this.age==1}[0]"/></li>

      [这个不懂]<li>投影:<s:propertyvalue="users.{^#this.age>1}.{age}"/></li>

      [这个不懂]<li>投影:<s:propertyvalue="users.{$#this.age>1}.{age}"/></li>

      [这个不懂]<li>投影:<s:propertyvalue="users.{$#this.age>1}.{age} == null"/></li>

      <hr/>

      [这个不懂]<li>[]:<s:propertyvalue="[0].username"/></li>

     

   </ol>

  

   <s:debug></s:debug>

</body>

</html>

 

具体理解:

1集合List,set map正常

2对象正常,普通方法正常,静态方法正常,新建对象正常

3 user对象在 jsp页面使用了get方法,set个人理解是在 传递参数的时候才起作用

4 剩下的投影不太理解,不知是否常用。

0 0
原创粉丝点击