Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

15.2. Struts Tags

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

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

15.2.1. property

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

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

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		
		

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>
</s:url>
 
<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>
</s:action>
		
		

15.2.6. HTML Form

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

15.2.6.2. textfield

			
<s:textfield name="variable"/>			
			
			

15.2.6.3. s:hidden

隱藏表單

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

15.2.6.4. 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>
</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>
			
			

15.2.7. iterator

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

15.2.8. if elseif else

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