panda

          IT高薪不是夢!!

          統計

          留言簿

          閱讀排行榜

          評論排行榜

          struts logic標簽使用詳解

          Logic 比較標簽(一)

          1.<logic:equal>

          判斷變量是否與指定的常量相等。例如:

          ???? <%

          ?????? pageContext.setAttribute("test",new Integer(100));

          ???? %>

          ???? <logic:equal value="100" name="test">

          ???????? test=100???? </logic:equal>

          2.<logic:greaterThan>

          判斷常量變量是否與指定的常量不相等。

          <html:link page="/greaterThan.jsp?test=123456">添加參數</html:link> //傳值

          <logic:greaterThan value="12347" parameter="test">

          ?????? true

          </logic:greaterThan>

          下面類似

          3.<logic:greaterEqual>

          判斷變量大小是否等于指定的常量。

          4.<logic:lessThan>

          判斷變量是否小于指定的常量。

          5.<logic:lessEqual>

          判斷變量是否小于等于指定的常量。

          Struts logic標簽(二)

          循環遍歷標簽<logic:iterate>

          該標簽用于在頁面中創建一個循環,以次來遍歷數組、Collection、Map這樣的對象。在Struts中經常用到!

          例如:

          <%

          String []testArray={"str0","str1","str2","str3","str4","str5"};

          pageContext.setAttribute("test",testArray);

          %>

          <logic:iterate id="array" name="test">

          ??????? <bean:write name="array"/>

          </logic:iterate>

          首先定義了一個字符串數組,并為其初始化。接著,將該數組存入pageContext對象中,命名為test1。然后使用logic:iterate標記的name屬性指定了該數組,并使用id來引用它,同時使用bean;write標記來將其顯示出來。

          還可以通過length屬性指定輸出元素的個數,offset屬性指定從第幾個元素開始輸出。例如:

          <logic:iterate id="array1" name="test1" length="3" offset="2">

          <bean:write name="array1"/><br>

          </logic:iterate>

          Struts logic標簽(三)

          <logic:match>

          <logic:notmatch>

          該標簽用于判斷變量中是否或者是否不包含指定的常量字符串。例如:

          <%

          ??????? pageContext.setAttribute("test","helloWord");

          %>

          <logic:match value="hello" name="test">

          ?????? hello 在helloWord中

          </logic:match>

          Match標記還有一個重要屬性,就是location屬性。location屬性所能取的值只有兩個,一個是"start",另一個是"end"。例如:

          <logic:match value="hello" name="test" location="start">

          ????????? helloWord以 hello開頭

          </logic:match>

          Struts logic存在標簽(四)

          <logic:present>

          <logic:notpresent>

          <logic:messagePresent>

          <logic:messageNotPresent>

          <logic:present>和<logic:notpresent>標簽主要用于判斷所指定的對象是否存在;

          例如:

          <%

          pageContext.setAttribute("test","testString");

          %>

          <logic:present name="test">

          ??????? true??

          </logic:present>

          <logic:present>和<logic:notpresent>標記有以下幾個常用屬性:

          header屬性:???? 判斷是否存在header屬性所指定的header信息。

          parameter屬性:判斷是否存在parameter屬性指定的請求參數。

          cookie屬性:???? 判斷cookie屬性所指定的同名cookie對象是否存在。

          name屬性:?????? 判斷name屬性所指定的變量是否存在。

          property屬性:和name屬性同時使用,當name屬性所指定的變量是一個JavaBean時,判斷property屬性所指定的對象屬性是否存在。

          <%

          ?????? Cookie cookie=new Cookie("name","value");

          ?????? response.addCookie(cookie);

          %>

          <logic:present cookie="name">

          ??????? true

          </logic:present>

          <logic:messagePresent>和<logic:messageNotPresent>這兩個標記是來判斷是否在request內存在特定的ActionMessages或ActionErrors對象。它們有幾個常用的屬性:

          name屬性:???? 指定了ActionMessages在request對象內存儲時的key值。

          message屬性:message屬性有兩種取值。當其為true時,表示使用Globals.MESSAGE_KEY做為從request對象中獲取ActionMessages的key值,此時無論name指定什么都無效;當其為false時,則表示需要根據name屬性所指定的值做為從request對象中獲取ActionMessages的key

          值,倘若此時未設置name屬性的值,則使用默認的Globals.ERROR_KEY。

          property屬性:指定ActionMessages對象中某條特定消息的key值。

          例如:

          ????? <%

          ???????? ActionErrors errors = new ActionErrors();

          ???????? errors.add("totallylost", new ActionMessage("application.totally.lost"));

          ???????? request.setAttribute(Globals.ERROR_KEY, errors);

          ???????? request.setAttribute("myerrors", errors);

          ????? %>

          ???????? <logic:messagesPresent name="myerrors">

          ?????????? Yes

          ???????? </logic:messagesPresent>

          Struts logic判空標簽(五)

          <logic:empty>

          <logic:notEmpty>

          該標簽用于判斷指定的字符是否為空。

          例如:

          ????? <%

          ??????? pageContext.setAttribute("test","");

          ????? %>

          ??

          ???? <logic:empty name="test">

          ???????? test 為空

          ???? </logic:empty>

          Struts logic轉發和重定向標簽(六)

          1.<logic:foward>轉發標簽

          該標簽用于進行全局轉發,使用該標簽的頁面一般不再編寫其他內容,因為隨著轉發,頁面將跳轉,原頁面中的內容也沒有意義了。例如:

          ????? this is a test

          <logic:forward name="welcome"/>

          ???? this is a new test

          2.<logic:redirect>重定向標簽

          該標簽用于進行重定向。具有屬性:

          href屬性:???? 將頁面重定向到href指定的完整外部鏈接。

          page屬性:???? 該屬性指定一個本應用內的一個網頁,標記將頁面重定向到這個新的網頁。

          forward屬性:該屬性與struts-config.xml中的<global-forward>內的子項相對應。即將頁面重定向到forward所指定的資源。

          posted on 2009-07-16 23:51 IT追求者 閱讀(519) 評論(0)  編輯  收藏 所屬分類: struts


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 抚宁县| 罗甸县| 双辽市| 拜城县| 石河子市| 商洛市| 平湖市| 永德县| 高阳县| 屯昌县| 山阳县| 阿巴嘎旗| 温州市| 偃师市| 和顺县| 兖州市| 洪江市| 连平县| 临沭县| 河源市| 南平市| 邹平县| 义乌市| 舒兰市| 彩票| 牟定县| 宜兴市| 盐山县| 永善县| 南安市| 临汾市| 黄平县| 新竹县| 蚌埠市| 安多县| 都兰县| 晋中市| 无棣县| 韶关市| 会东县| 拜城县|