</html:link>
解析后的代码: <a href="/struts-exercise-taglib/html-link.do?booleanProperty=false"> Boolean via paramId, paramName, and paramValue </a>
另外,还能使用带name属性的Map来实现传递多个参数: <% java.util.HashMap newValues = new java.util.HashMap(); newValues.put("floatProperty", new Float(444.0)); newValues.put("intProperty", new Integer(555)); newValues.put("stringArray", new String[] { "Value 1", "Value 2", "Value 3" }); pageContext.setAttribute("newValues", newValues); %> ... <html:link action="/html-link" name="newValues"> Float, int, and stringArray via name (Map) </html:link>
你也能够链接到Map类型的action上,上面的代码解析后的结果: <html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer"> <tr><td><%= pageContext.getAttribute("msg") %></td></tr> </html:messages>
2.) select和option标签 <html:select> 的属性:property-与ActionForm中的某个属性对应;size-显示option的数目;multiple-默认为fales,表示不能多选,当设定为true时,property对应的ActionForm的属性必须为数组。 <html:select property="name" size=6 multiple="true"> <html:option>的属性:key、local、bundle-指定Resource Bundle中的内容。 例如 <html:option value="color1">Orange</html:option> <html:option value="color1" bundle="htmlselect.Colors" key="htmlselect.red"/> 它和配置文件中的<message-resources>元素的key属性匹配 --> <message-resource parmeter="HtmlSelectColors" key="htmlselect.Colors"/> <message-resource>中配置的资源文件为HtmlSelectColors.properties,相关内容为 htmlselect.red=RED <html:options>标签,提供了一组<option>元素,在<html:select>元素中可以包含多个<html:options>元素。非常灵活,可以取得集合或数组中的值。 例1 <html:options collection="coll" property="value" labelProperty="label" /> 这指在coll的集合中存放了options,value指实际能被提交的值,label是显示给用户的值。 例2 <html:options property="value" labelProperty="label" /> collection属性不被指定时,将使用表单相关的form bean,form bean中value属性存放option value,label属性值显示给用户。 例3 <html:options name="valueBean" property="values" labelName="labelsBean" labelProperty="labels" /> 这个意思是value值存放在名为valueBean的bean的vlaues属性中,它是一个collection;label值也是同样的意思。 <html:optionsCollection>标签,和<html:options>的用法很相似。 例如 <html:select property="custId"><html:optionsCollection property="customers" label="name" value="custId" /></html:select> 这个标签和org.apache.structs.util.LabelValueBean结合的很好,如果把label和value都放到这个对象中,可以很简单的这样应用: <html:select property="custId"><html:optionsCollection property="customers" /></html:select> JSP Struts之Bean标签库详解 Bean 标签库 此标签库和Java Bean有很强的关联性,设计的本意是要在JSP 和JavaBean 之间提供一个接口。Struts 提供了一套小巧有用的标签库来操纵JavaBean和相关的对象:cookie、 header、 parameter、 define、write、message、 include、page、resource、size、struts。 1. bean:cookie、bean:header、bean:parameter 这三个标签用来重新得到cookie, request header和request parameter。 bean:header和bean:parameter标签定义了一个字符串;bean:cookie标签定义了一个Cookie对象。你可以使用value属性做为默认值。如果找不到指定的值,且默认值没有设定的话,会抛出一个request time异常。如果你期望返回多个值的话,可把multiple属性设为true。 <bean:cookie id="sessionID" name="JSESSIONID" value="JSESSIONID-ISUNDEFINED"/> // 这段代码定义了一个名为sessionID的脚本变量,如果找不到一个名为JSESSIONID的cookie,那sessionID // 的值就被设置为JSESSIONID-ISUNDEFINED。
2. 下面代码会输出一些Cookie对象的一些属性: <jsp:getProperty name="sessionID " property="comment"/> … <jsp:getProperty name="sessionID" property="domain"/> … <jsp:getProperty name="sessionID" property="maxAge"/> … <jsp:getProperty name="sessionID" property="path"/> … <jsp:getProperty name="sessionID" property="value"/> … <jsp:getProperty name="sessionID" property="version"/> …
3. 下面是在request中输出所有header的例子: <% java.util.Enumeration names =((HttpServletRequest) request).getHeaderNames(); %> … <% while (names.hasMoreElements()) {
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一页 1 2 34 5 下一页
上一篇:jsp 自定义分页标签 下一篇:jsp中的数据库编程
|