JAVA

          人生若只如初見,何事秋風(fēng)悲畫扇。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            50 隨筆 :: 25 文章 :: 157 評(píng)論 :: 0 Trackbacks

            剛剛才發(fā)現(xiàn)原來(lái)在JSP頁(yè)面,當(dāng)用到其腳本,如在<%=REG%>表達(dá)式中,原來(lái)REG是可以直接從此JSP頁(yè)面的STRUTS中定義而來(lái)!

            從bean標(biāo)簽中引用,比如:

          < bean:define? id ="birthdayInfo" ?name ="person" ?property ="info.birthday" />

            看struts參考文檔中,bean:define 是指定義一個(gè)在指定范圍內(nèi)bean相關(guān)屬性的腳本變量(Define a scripting variable based on the value(s) of the specified bean property)

            此中,person可能是在request等中預(yù)先已經(jīng)定義好的DTO等等(這里暫時(shí)不是我們所要關(guān)注的啦),然后直接引用:

          <% = ?PrintUtil.printTimeArea((UtilDateDTO)birthdayInfo)? %>

            PrintUtil與UtilDateDTO均是在JSP頁(yè)面預(yù)先包含進(jìn)來(lái)的(也不用關(guān)注),這些都是后臺(tái)部分的處理了,這里主是說(shuō)明在JSP中其腳本如何引用STRUTS標(biāo)簽中的變量值。

            
            也可以直接從logic中引用,如:

          < logic:iterate? id ="detailsdto" ?name ="eduCalendar"
          ????????type
          ="com.jbbis.netedu.eduadmin.dto.CalendarDetailDTO"
          ????????property
          ="details" >
          ????????
          <% = ?PrintUtil.printTimeArea((CalendarDetailDTO)detailsdto)? %>
          ???????
          </ logic:iterate >


            其原理一樣的。
          ?????????logic:iterate是用來(lái)迭代指定范圍內(nèi)一些特定的集合容器(Custom tag that iterates the elements of a collection, which can be either an attribute or the property of an attribute. The collection can be any of the following: an array of objects, an Enumeration, an Iterator, a Collection (which includes Lists, Sets and Vectors), or a Map (which includes Hashtables) whose elements will be iterated over.)

            應(yīng)用示例:
            在DTO中我的一屬性---生日,在實(shí)體與DTO均定義為L(zhǎng)ong,所以假如有一個(gè)為1950-01-01生日的數(shù)據(jù),那么在DTO與實(shí)體中就表示為631124235983

          <%
          java.text.DateFormat?_fmt?
          = new ?java.text.SimpleDateFormat( " yyyy-MM-dd " ,?Locale.SIMPLIFIED_CHINESE);
          %>

          ??

          < logic:notEmpty? name ="dto" ?property ="birthday" >
          ?????
          < bean:define? id ="curbirthday" ?name ="dto" ?property ="birthday" />
          ?????
          <% = _fmt.format( new ? Date ((( Long )curbirthday).longValue()))? %>
          ?????
          </ logic:notEmpty ></ span ></ td >



            當(dāng)然這樣在JSP中加了個(gè)<%=%>符號(hào),要不就在DTO中額外為生日另一個(gè)屬性提供對(duì)生日的字符顯示("yyyy-MM-dd")。

            在JSP中恰當(dāng)應(yīng)用相關(guān)標(biāo)簽,不僅編程方便,而且代碼也可以美觀不少。

          posted on 2006-05-25 18:42 Jkallen 閱讀(1537) 評(píng)論(0)  編輯  收藏 所屬分類: JEE學(xué)習(xí) 、其它開源
          主站蜘蛛池模板: 平陆县| 汽车| 百色市| 留坝县| 嫩江县| 肥乡县| 永寿县| 汝南县| 云龙县| 全南县| 蒙山县| 苗栗市| 鸡泽县| 定远县| 南丰县| 辰溪县| 汕尾市| 德庆县| 安龙县| 炎陵县| 获嘉县| 湖北省| 丹东市| 新营市| 湘潭市| 密云县| 嘉义县| 宿松县| 东乡族自治县| 安图县| 富蕴县| 封丘县| 卓尼县| 平度市| 台山市| 张掖市| 凤山县| 岗巴县| 积石山| 静海县| 东乌|