Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About

15.2. Struts Tags

使用Struts Tags 需要在jsp页面中加入下面一行。

<%@ taglib prefix="s" uri="/struts-tags" %>

15.2.1. property

<%@ taglib prefix="s" uri="/struts-tags" %>
Hello, <s:property value="name"/>
<s:property value="messageStore.message" />
<s:property value="#session.user.username" />

<s:bean name="cn.netkiller.Person" var="personBean" />
<s:property value="#personBean.name" />

15.2.2. set

<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转义,如果你的字符串中含有&, <, > 等字符输出就会出现 &amp;, &lt;, &gt; escapeHtml="false" 可以禁止这样的转义,原样输出。

<s:property value="url" escapeHtml="false"/>		


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		

15.2.3. url

<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>
<p><a href="${helloLink}">Hello Bruce Phillips</a></p>


15.2.4. s:include

<s:include value="/pages/example.jsp"></s:include>			

15.2.5. s:action

<%@ 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>

15.2.6. HTML Form form

<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> textfield

<s:textfield name="variable"/>			 s:hidden


<s:hidden id="unique" name="form.unique" value=""/>			 select

<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>
<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>

15.2.7. iterator

<s:iterator value="people">
	<s:property value="lastName"/>, <s:property value="firstName"/>

15.2.8. if elseif else

<s:if test="%{false}">
    <div>Will Not Be Executed</div>
<s:elseif test="%{true}">
    <div>Will Be Executed</div>
    <div>Will Not Be Executed</div>