struts的bean標(biāo)記庫是對jsp的標(biāo)準(zhǔn)標(biāo)記庫的增強(qiáng),除了提供基本的jsp:userBean、jsp:setPRoperty等標(biāo)記的基本功能,還支持對多種對象的操作,從多種對象生產(chǎn)javaBean,提供了更方便的讀、寫B(tài)ean的方法。
以下是從其官方網(wǎng)站的User Guide摘抄的對其功能的描述,
IntrodUCe A String Constant - 從字符串常量創(chuàng)建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創(chuàng)建新的引用(type屬性聲明該引用的類型)
<bean:define id="foo" name="bar"/>
<bean:define id="baz" name="bop" type="com.mycompany.MyBopClass"/>
Copy An Existing Bean Property - 從已存在的bean的屬性創(chuàng)建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創(chuàng)建bean。假如指定的cookie不存在則會拋出運(yùn)行時異常 - 因此,常和 <logic:present cookie="xxx"> 標(biāo)簽一起使用來保證cookie的存在。 通過指定multiple屬性,可以從多個同名cookie創(chuàng)建一個包含多個cookie的數(shù)組。
<bean:cookie id="foo" name="cookiename"/>
<bean:cookie id="all" name="JSESSIONID" multiple="true"/>
Copy A Request Header - 從請求頭創(chuàng)建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).(由于學(xué)識有限,這段還不太理解,所以沒有翻譯)
<bean:include id="text" name="/generateXml?param1=a¶m2=b"/>
Copy A JSP Implicitly Defined Object - 從JSP內(nèi)置對象建立bean。
<bean:page id="app" property="application"/> <bean:page id="sess" property="session"/>
新聞熱點(diǎn)
疑難解答
圖片精選