JAVA

人生若只如初见,何事秋风悲画扇。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  50 随笔 :: 25 文章 :: 157 评论 :: 0 Trackbacks

  刚刚才发现原来在JSP页面,当用到其脚本,如在<%=REG%>表达式中,原来REG是可以直接从此JSP页面的STRUTS中定义而来!

  从bean标签中引用,比如:

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

  看struts参考文档中,bean:define 是指定义一个在指定范围内bean相关属性的脚本变量(Define a scripting variable based on the value(s) of the specified bean property)

  此中,person可能是在request等中预先已经定义好的DTO等等(这里暂时不是我们所要关注的啦),然后直接引用:

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

  PrintUtil与UtilDateDTO均是在JSP页面预先包含进来的(也不用关注),这些都是后台部分的处理了,这里主是说明在JSP中其脚本如何引用STRUTS标签中的变量值。

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

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


  其原理一样的。
         logic:iterate是用来迭代指定范围内一些特定的集合容器(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.)

  应用示例:
  在DTO中我的一属性---生日,在实体与DTO均定义为Long,所以假如有一个为1950-01-01生日的数据,那么在DTO与实体中就表示为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 >



  当然这样在JSP中加了个<%=%>符号,要不就在DTO中额外为生日另一个属性提供对生日的字符显示("yyyy-MM-dd")。

  在JSP中恰当应用相关标签,不仅编程方便,而且代码也可以美观不少。

posted on 2006-05-25 18:42 Jkallen 阅读(1517) 评论(0)  编辑  收藏 所属分类: JEE学习其它开源

只有注册用户登录后才能发表评论。


网站导航: