龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

struts的bean标签库

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
struts的bean标记库是对jsp的标准标记库的增强,除了提供基本的jsp:userBean、jsp:setProperty等标记的基本功能,还支持对多种对象的操作,从多种对象生产JavaBean,提供了更方便的读、写Bea

  
   

          struts的bean标记库是对jsp的标准标记库的增强,除了提供基本的jsp:userBean、jsp:setProperty等标记的基本功能,还支持对多种对象的操作,从多种对象生产JavaBean,提供了更方便的读、写Bean的方法。

          以下是从其官方网站的User Guide摘抄的对其功能的描述,

     

  IntrodUCe A String Constant - 从字符串常量创建bean

      <bean:define id="foo" value="This is a new String"/>
      <bean:define id="bar" value='<%= "Hello, " + user.getName() %>'/>
      <bean:define id="last" scope="session"
                   value='<%= request.getRequestURI() %>'/>

  
  Copy An Existing Bean - 为已有的bean创建新的引用(type属性声明该引用的类型)

      <bean:define id="foo" name="bar"/>
      <bean:define id="baz" name="bop" type="com.mycompany.MyBopClass"/>

  
  Copy An Existing Bean Property - 从已存在的bean的属性创建bean。可以使用的bean的属性有三种:simple, nested, or indexed。

      <bean:define id="foo" name="bar" property="baz" scope="request"     toScope="session"/>    <bean:define id="bop" name="user" property="role[3].name"/>
  Other Struts Copying Tags
  Copy A Cookie - 从cookie创建bean。假如指定的cookie不存在则会抛出运行时异常 - 因此,常和 <logic:present cookie="xxx"> 标签一起使用来保证cookie的存在。 通过指定multiple属性,可以从多个同名cookie创建一个包含多个cookie的数组。

      <bean:cookie id="foo" name="cookiename"/>
      <bean:cookie id="all" name="JSESSIONID" multiple="true"/>

  
  Copy A Request Header - 从请求头创建bean。 (其余说明同上)

      <bean:header id="agent" name="User-Agent"/>    <bean:header id="languages" name="Accept-Language" multiple="true"/>
  Copy A Dynamically Created Response - You can generate an internal request to the application you are running, and turn the response data that is returned from that request into a bean (of type String). One possible use for this technique is to acquire dynamically created XML formatted data that will be stored in a bean and later manipulated (such as by applying an XSLT stylesheet). If the current request is part of a session, the generated request for the include will also include the session identifier (and thus be considered part of the same session).(由于学识有限,这段还不太理解,所以没有翻译)

      <bean:include id="text" name="/generateXml?param1=a&param2=b"/>
  Copy A JSP Implicitly Defined Object - 从JSP内置对象建立bean。

      <bean:page id="app" property="application"/>    <bean:page id="sess" property="session"/>
  
  

精彩图集

赞助商链接