标签库
|
说明
|
HTML
标签
|
用来创建能够和
Struts
框架和其他相应的
HTML
标签交互的
HTML
输入表单
|
Bean
标签
|
在访问
JavaBeans
及其属性,以及定义一个新的
bean
时使用
|
Logic
标签
|
管理条件产生的输出和对象集产生的循环
|
Template
标签
|
随着
Tiles
框架包的出现,此标记已开始减少使用
|
Nested
标签
|
增强对其他的
Struts
标签的嵌套使用的能力
|
属性
|
说明
|
id
|
命名自定义标签创建时的脚本变量名。
|
name
|
指出关键字值,在该关键字下可以找到一个存在的
bean
。如果给出了
scope
属性,则仅仅在
scope
中查找。否则,根据标准的顺序在各种
scope
中查找:
(page, request, session, or application)
。
|
property
|
指出
bean
中的某个属性,可以在其中检索值。如果没有标明,则使用对象本身的值。
|
scope
|
定义了
Bean
在哪个范围
(page, request, session, or application)
中被查找。如果没有标明按顺序查找。脚本变量
(
见
id)
将在相同的范围中创建。
|
Property="foo.bar.baz" 这相当于进行下面的调用: getFoo().getBar().getBaz() ; 或者做为 setter : getFoo().getBar().setBaz(value) ; |
错误:
<html:link href="'<%= "/" + name %>/index.jsp>'> 正确: <html:link href="'<%= "/" + name + "/index.jsp" %>'> // 表达式必须提供整个属性值 |
<html:htmllocale=\"true\"> 此行代码解析后: <htmllang=\"en\"> |
<html:base/> 此行代码解析后: <basehref=\"http://www.mymain.com/myStrutsApp/testing.jsp\"> |
<html:imgpage=\"/logo.gif\"height=\"50\" width=\"200\"alt=\"WebLogo\"/>
|
<html:linkpage=\"/index.html\">Clickdemo</html:link> 此行代码解析后: <ahref=\"/index.html\">Clickdemo</a> |
<html:formaction=\"/login\"> 如果你有上述一个标签 ,那么你的 Struts 配置文件的元素中必须有一个如下显示为粗体的元素: <action-mappings> <actionpath=\"/login\" type=\"com.javapro.struts.LoginAction\" name=\"loginForm\" scope=\"request\" input=\"/login.jsp\"> <forwardname=\"success\"path=\"/mainMenu.jsp\"/> </action> . . . </action-mappings> // 这就是说一个 form 标签是和 formbean 相关联的。 |
<body> <html:formaction=\"/login\"focus=\"password\"> UserName:<html:textproperty=\"userName\"/> <br>Password:<html:textproperty=\"password\"/> <br><html:submit/> </html:form> </body> 代码解析后: <body> <formname=\"loginForm\"method=\"post\" action=\"/myStrutsApp/login.do\"> UserName:<inputtype=\"text\"name=\"userName\" value=\"\"> <br>Password:<inputtype=\"text\" name=\"password\"value=\"\"> <br><inputtype=\"submit\" value=\"Submit\"> </form> <scriptlanguage=\"JavaScript\" type=\"text/javascript\"> <!-- if(document.forms[\"loginForm\"].elements[\"password\"].type!=\"hidden\") document.forms[\"loginForm\"].elements[\"password\"].focus() //--> </script> </body> |
<html:passwordproperty=\"password\"redisplay=\"false\"/>
|
<html:selectproperty=\"color\"size=\"3\"> <html:optionvalue=\"r\">red</html:option> <html:optionvalue=\"g\">green</html:option> <html:optionvalue=\"b\">blue</html:option> </html:select> |
<html:link page="/html-link.do"> Linking with the page attribute. </html:link> |
<html:link href="/struts-exercise-taglib/html-link.do"> Using Href </html:link> |
<html:link href="http://otherserver/strutsTut/html-link.do"> Using Href </html:link> |
<html:link action="/html-link"> Using Action attribute </html:link> |
<html:link page="/htmllink.do?doubleProp=3.3&longProp=32"> Double and long via hard coded changes </html:link> |
<html:link page="/html-link.do" paramId="booleanProperty" paramName="testbean" paramProperty="nested.booleanProperty"> Boolean via paramId, paramName, and paramValue </html:link> |
<a href="/struts-exercise-taglib/html-link.do?booleanProperty=false"> Boolean via paramId, paramName, and paramValue </a> |
<% 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> |
<html:messages property="property2" message="true" id="msg" header="messages.header" footer="messages.footer"> <tr><td><%= pageContext.getAttribute("msg") %></td></tr> </html:messages> |
<bean:cookie id="sessionID" name="JSESSIONID" value="JSESSIONID-ISUNDEFINED"/> // 这段代码定义了一个名为 sessionID 的脚本变量,如果找不到一个名为 JSESSIONID 的 cookie ,那 sessionID // 的值就被设置为 JSESSIONID-ISUNDEFINED 。 |
<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"/> … |
<% java.util.Enumeration names =((HttpServletRequest) request).getHeaderNames(); %> … <% while (names.hasMoreElements()) { String name = (String) names.nextElement(); %> <bean:header id="head" name="<%= name %>"/> … <%= name %> … <%= head %> … <% } %> |
<bean:parameter id="param1" name="param1"/> <bean:parameter id="param2" name="param2" multiple="true"/> // 此处定义了一个 param2[] 。 <bean:parameter id="param3" name="param3" value="UNKNOWN VALUE"/> |
<bean:header id="browser" name="User-Agent"/> <P>You are viewing this page with: <bean:write name="browser"/></P> ---------------------------------------------------------------------------------------------------------------------------------- <bean:cookie id="username" name="UserName" scope="session" value="New User" /> <P>Welcome <bean:write name="username" property="value"/!</P> // 根据 cookie 创建一个新的 Bean ,如果用户名称已经存储在 cookie 中,它就不显示为一个新用户。 |
<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() %>'/> |
<bean:define id="foo" name="bar"/> <bean:define id="baz" name="bop" type="com.mycompany.MyClass"/> //定义脚本变量的类型,默认为 Object |
<bean:define id="bop" name="user" property="role[3].name"/> <bean:define id="foo" name="bar" property="baz" scope="request" toScope="session"/> //toScope 属性指新 bean 的 scope ,默认为 page |
<bean:include id="footerSpacer" page="/long/path/footerSpacer.jsp"/> 然后你能够在多个地方 (scope 为 page) 调用: <bean:write name="footerSpacer" /> |
评论