隨筆 - 12  文章 - 20  trackbacks - 0
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          (先定義一個action,有個username字段,假設value="song"想傳遞到頁面上)

          public class Login extends ActionSupport {

              private String username;
             
              public String execute() throws Exception {
                  return INPUT;
              }

              public String getUsername() {
                  return username;
              }

              public void setUsername(String username) {
                  this.username = username;
              }

          }

          在jsp頁面中用以下四種方法可以實現:

          1. <s:property value="username"/>
          2. ${username}   

          ${}為EL表達式
          3. <s:property value="#request.username"/>  (#session. #application.類似)

          (1)#相當于ActionContext().getContext

          ActionContext 中的主要對象: parameters, attr, request, session, application

          如:

          ActionContext().getContext().getSession().get(“kkk”)

          #session.kkk

          ActionContext().getContext().get(“person”)

          #person

          (2)

          Map

          map.get(“foo”)

          map[‘foo’]      map.foo

          map.get(1)

          map[1]

          Map map = new HashMap()

          map.put(“k1”, “v1”);   map.put(“k2”,”v2”);

          #{“k1

           

          (3)篩選 投影

          篩選 collection.{? expr }    #this 代表當前循環到的object

          投影 collection.{ expr }

           

          children.{name}

          (投影)得到 Collection<String> names, 只有孩子名字的list

          children.{?#this.age>2}

          (篩選)得到 collection<Person> age>2的記錄

          children.{?#this.age<=2}.{name}

          先篩選再投影

          children.{name+’->’+mother.name}

          (篩選)得到元素為 str->str  的集合

          總結:

           #的三種用途

          1.       引用 ActionContext 中的object       #person 

          2.       動態創建map                        #{1:’a’, 2:’b’}

          3.       對集合進行篩選(#this)               #this


          4. <s:property value="%{username}"/>

          posted on 2008-12-23 15:06 沖出銀河系 閱讀(1134) 評論(0)  編輯  收藏 所屬分類: struts2
          主站蜘蛛池模板: 鄱阳县| 攀枝花市| 丹棱县| 民勤县| 延庆县| 德钦县| 南和县| 苍南县| 苍梧县| 元朗区| 鹿邑县| 梅州市| 普宁市| 阿合奇县| 苏尼特左旗| 晋州市| 宣武区| 芦溪县| 安达市| 饶平县| 孟州市| 富顺县| 大埔区| 咸阳市| 砀山县| 乳源| 阳春市| 青阳县| 永寿县| 阿拉善左旗| 报价| 辰溪县| 五原县| 钟祥市| 永平县| 原平市| 上林县| 海南省| 旬阳县| 西畴县| 丁青县|