panda

          IT高薪不是夢!!

          統(tǒng)計

          留言簿

          閱讀排行榜

          評論排行榜

          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">添加參數(shù)</html:link> //傳值

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

          ?????? true

          </logic:greaterThan>

          下面類似

          3.<logic:greaterEqual>

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

          4.<logic:lessThan>

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

          5.<logic:lessEqual>

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

          Struts logic標簽(二)

          循環(huán)遍歷標簽<logic:iterate>

          該標簽用于在頁面中創(chuàng)建一個循環(huán),以次來遍歷數(shù)組、Collection、Map這樣的對象。在Struts中經(jīng)常用到!

          例如:

          <%

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

          pageContext.setAttribute("test",testArray);

          %>

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

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

          </logic:iterate>

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

          還可以通過length屬性指定輸出元素的個數(shù),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屬性指定的請求參數(shù)。

          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內(nèi)存在特定的ActionMessages或ActionErrors對象。它們有幾個常用的屬性:

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

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

          值,倘若此時未設(shè)置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轉(zhuǎn)發(fā)和重定向標簽(六)

          1.<logic:foward>轉(zhuǎn)發(fā)標簽

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

          ????? this is a test

          <logic:forward name="welcome"/>

          ???? this is a new test

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

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

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

          page屬性:???? 該屬性指定一個本應(yīng)用內(nèi)的一個網(wǎng)頁,標記將頁面重定向到這個新的網(wǎng)頁。

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

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


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 开江县| 上蔡县| 邓州市| 阳曲县| 衡南县| 株洲县| 建湖县| 阆中市| 陈巴尔虎旗| 扶沟县| 托里县| 泌阳县| 连山| 舒城县| 洪雅县| 师宗县| 河北省| 大洼县| 松滋市| 潮安县| 石林| 密山市| 唐海县| 页游| 繁峙县| 垦利县| 湄潭县| 建水县| 台前县| 安徽省| 敖汉旗| 旬阳县| 黄龙县| 济源市| 延庆县| 和平县| 鄂伦春自治旗| 塔城市| 安义县| 比如县| 安国市|