服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

struts的bean标签库


 

        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"/>
copy a request parameter - 从请求参数建立bean。(其余说明同bean:cookie)

    <bean:parameter id="name" name="name"/>
    <bean:header id="options" name="option" multiple="true"/>


copy a web application resource - 从web应用程序资源建立一个包含web应用程序资源字符串、或一个inputstream输入流以供读取其中的资源的bean。

    <bean:resource id="deployment" name="/web-inf/web.xml"/>    <bean:resource id="stream" name="/web-inf/web.xml"                   input="true"/>
copy a struts configuration object - 从struts标准配置对象建立bean。

    <bean:struts id="form" formbean="customerform"/>
    <bean:struts id="fwd" forward="success"/>
    <bean:struts id="map" mapping="/savecustomer"/>

 

--------------------------------------------------------------------------------

bean output
render an internationalized message - 处理国际化message。在使用前要预先对该资源进行读取、配置等操作。

    <bean:message key="label.cancel"/>
    <bean:message key="message.hello" arg0='<%= user.getfullname() %>'/>


render a bean or bean property - 输出bean或bean的属性。

    <bean:write name="username"/>
    <bean:write name="user" property="fullname"/>
    <bean:write name="customer" property="orders[2].partnumber"
                scope="session"/>

 


 
  
 

扫描关注微信公众号