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¶m2=b"/>
Copy A JSP Implicitly Defined Object - 從JSP內置對象建立bean。
<bean:page id="app" property="application"/> <bean:page id="sess" property="session"/>