Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

17.2. Struts Tags

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

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

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

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

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

		
		

17.2.4. s:include

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

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

17.2.6. HTML Form

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

17.2.6.2. textfield

			
<s:textfield name="variable"/>			
			
			

17.2.6.3. s:hidden

隐藏表单

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

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

17.2.7. iterator

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

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