Struts2分为四类标签:控制标签、数据标签、表单标签、Ajax标签
都需要引入的标签
<%@ taglib prefix="s" uri="/struts-tags"%>
控制标签
IF和ELSE标签:IF标签可以单独使用、也可以与ELSE IF标签连用,
<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>
ITERATOR标签:
<s:iterator value="days">
<p>day is: <s:property/></p>
</s:iterator>
MERGE标签:
<s:merge var="myMergedIterator">
<s:param value="%{myList1}" />
<s:param value="%{myList2}" />
<s:param value="%{myList3}" />
</s:merge>
APPEND标签:
<s:append var="myAppendIterator">
<s:param value="%{myList1}" />
<s:param value="%{myList2}" />
<s:param value="%{myList3}" />
</s:append>
GENERATOR标签:
<s:generator val="%{'aaa,bbb,ccc,ddd,eee'}">
<s:iterator>
<s:property /><br/>
</s:iterator>
</s:generator>
数据标签
ACTION标签
<s:action name="actionTagAction" executeResult="true" />
INCLUDE标签
<-- First Syntax -->
<s:include value="myJsp.jsp" />
<-- Second Syntax -->
<s:include value="myJsp.jsp">
<s:param name="param1" value="value2" />
<s:param name="param2" value="value2" />
</s:include>
<-- Third Syntax -->
<s:include value="myJsp.jsp">
<s:param name="param1">value1</s:param>
<s:param name="param2">value2</s:param>
</s:include
BEAN标签
<s:bean name="org.apache.struts2.util.Counter" var="counter">
<s:param name="first" value="20"/>
<s:param name="last" value="25" />
</s:bean>
DATE标签
<s:date name="person.birthday" format="dd/MM/yyyy" />
<s:date name="person.birthday" format="%{getText('some.i18n.key')}" />
<s:date name="person.birthday" nice="true" />
<s:date name="person.birthday" />
param标签
<pre>
<ui:component>
<ui:param name="key" value="[0]"/>
<ui:param name="value" value="[1]"/>
<ui:param name="context" value="[2]"/>
</ui:component>
</pre>
property标签
<s:push value="myBean">
<!-- Example 1: -->
<s:property value="myBeanProperty" />
<!-- Example 2: -->TextUtils
<s:property value="myBeanProperty" default="a default value" />
</s:push>
push标签
<s:push value="user">
<s:propery value="firstName" />
<s:propery value="lastName" />
</s:push>
set标签
<s:set name="myenv" value="environment.name"/>
<s:property value="myenv"/>
text标签
<!-- First Example -->
<s:i18n name="struts.action.test.i18n.Shop">
<s:text name="main.title"/>
</s:i18n>
<!-- Second Example -->
<s:text name="main.title" />
<!-- Third Examlpe -->
<s:text name="i18n.label.greetings">
<s:param >Mr Smith</s:param>
</s:text>
url标签
<-- Example 1 -->
<s:url value="editGadget.action">
<s:param name="id" value="%{selected}" />
</s:url>
<-- Example 2 -->
<s:url action="editGadget">
<s:param name="id" value="%{selected}" />
</s:url>
<-- Example 3-->
<s:url includeParams="get">
<s:param name="id" value="%{'22'}" />
</s:url>
表单标签
body中的内容
<!--简单UI标签-->
<s:div>Email Form</s:div>
<s:text name="Please fill in the form below:" />
<s:form action="hello" method="post" enctype="multipart/form-data">
<s:hidden name="secret" value="abracadabra"/>
<s:textfield key="email.from" name="from" />
<s:password key="email.password" name="password" />
<s:textfield key="email.to" name="to" />
<s:textfield key="email.subject" name="subject" />
<s:textarea key="email.body" name="email.body" />
<s:label for="attachment" value="Attachment"/>
<s:file name="attachment" accept="text/html,text/plain" />
<s:token />
<s:submit key="submit" />
</s:form>
<!--群组UI标签-->
<s:form action="hello.action">
<s:radio label="Gender" name="gender" list="{'male','female'}" />
<s:checkboxlist label="Hobbies" name="hobbies"
list="{'sports','tv','shopping'}" />
</s:form>
<!--选择UI标签-->
<s:form action="login.action">
<s:select name="username" label="Username" list="{'Mike','John','Smith'}" />
<s:select label="Company Office" name="mySelection" value="%{'America'}"
list="%{#{'America':'America'}}">
<s:optgroup label="Asia" list="%{#{'India':'India','China':'China'}}" />
<s:optgroup label="Europe"
list="%{#{'UK':'UK','Sweden':'Sweden','Italy':'Italy'}}" />
</s:select>
<s:combobox label="My Sign" name="mySign"
list="#{'aries':'aries','capricorn':'capricorn'}"
headerKey="-1" headerValue="--- Please Select ---" emptyOption="true"
value="capricorn" />
<s:doubleselect label="Occupation" name="occupation"
list="{'Technical','Other'}" doubleName="occupations2"
doubleList="top == 'Technical' ?
{'I.T', 'Hardware'} : {'Accounting', 'H.R'}" />
</s:form>
Ajax标签
需要引入的标签
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
body中的内容
<s:form>
<sx:autocompleter label="Favourite Colour" list="{'red','green','blue'}" />
<br />
<sx:datetimepicker name="deliverydate" label="Delivery Date"
displayFormat="dd/MM/yyyy" />
<br />
<s:url id="url" value="/hello.action" />
<sx:div href="%{#url}" delay="2000">
Initial Content
</sx:div>
<br/>
<sx:tabbedpanel id="tabContainer">
<sx:div label="Tab 1">Tab 1</sx:div>
<sx:div label="Tab 2">Tab 2</sx:div>
</sx:tabbedpanel>
</s:form>