知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
使用Struts Tags 需要在jsp頁面中加入下面一行。
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Hello</title> </head> <body> Hello, <s:property value="name"/> </body> </html>
<s:property value="messageStore.message" /> <s:property value="#session.user.username" /> <s:bean name="cn.netkiller.Person" var="personBean" /> <s:property value="#personBean.name" />
<s:set var="personName" value="person.name"/> Hello, <s:property value="#personName"/> <s:set var="janesName">Jane Doe</s:set> <s:property value="#janesName"/>
禁止HTML轉義,如果你的字元串中含有&, <, > 等字元輸出就會出現 &, <, > escapeHtml="false" 可以禁止這樣的轉義,原樣輸出。
<s:property value="url" escapeHtml="false"/>
https://struts.apache.org/docs/property.html
Name Required Default Evaluated Type Description default false false String The default value to be used if value attribute is null escapeCsv false false false Boolean Whether to escape CSV (useful to escape a value for a column) escapeHtml false true false Boolean Whether to escape HTML escapeJavaScript false false false Boolean Whether to escape Javascript escapeXml false false false Boolean Whether to escape XML
<p><a href="<s:url action='hello'/>">Hello World</a></p> <s:url action="hello" var="helloLink"> <s:param name="userName">Bruce Phillips</s:param> </s:url> <p><a href="${helloLink}">Hello Bruce Phillips</a></p>
<%@ taglib prefix="s" uri="/struts-tags" %> <s:action name="index" namespace="/news" executeResult="true" />
<s:action name="index" namespace="/member" executeResult="true"> <s:param name="name">Neo</s:param> </s:action>
<p>Get your own personal hello by filling out and submitting this form.</p> <s:form action="hello"> <s:textfield name="userName" label="Your name" /> <s:submit value="Submit" /> </s:form>
隱藏表單
<s:hidden id="unique" name="form.unique" value=""/>
<s:select name="city" list="{'Beijing','Shanghai','Guangdong','Shenzhen'}" theme="simple" headerKey="Shenzhen" headerValue="Shenzhen"></s:select> <select name="city" id="searchCriteriaForm_city"> <option value="Shenzhen">Shenzhen</option> <option value="Beijing">Beijing</option> <option value="Shanghai">Shanghai</option> <option value="Guangdong">Guangdong</option> <option value="Shenzhen">Shenzhen</option> </select>
<s:select name="city" id="city" list="#{1:'Beijing',2:'Shanghai',3:'Guangdong',4:'Shenzhen'}" label="city" listKey="key" listValue="value" headerKey="4" headerValue="Shenzhen" /> <select name="city" id="city"> <option value="4">Shenzhen</option> <option value="1">Beijing</option> <option value="2">Shanghai</option> <option value="3">Guangdong</option> <option value="4">Shenzhen</option> </select>
<s:iterator value="people"> <s:property value="lastName"/>, <s:property value="firstName"/> </s:iterator>