struts2标签的使用总结

0、在页面中通过<%@taglib prefix="s" uri="/struts-tags"%>形式导入,该标签文件在struts2-core-2.0.14\META-INF\struts-tags.tld

1、当出现这种形式List<Map<String,String>> all,即list中存map时前台应该怎么循环输出,实现如下:

<select name="" class="searchArea_input_AreaSelect">
	<option>地区选择</option>
	<s:if test="all != null">
		<s:iterator value="all" id="temp">
			<s:iterator value="temp" id="mapElement">
				<option value="${key }">${value }</option>
			</s:iterator>
		</s:iterator>
	</s:if>
</select>

2、使用标签时需要以(xxxxx.....)格式显示内容时,处理如下

<s:if test="news != null">
	<s:iterator value="news">
		<tr>
			<td height="83">
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td height="30px" class="TDZX_title">
							<a href="#">${title }</a>
						</td>
					</tr>
					<tr>
						<td height="53px" class="TDZX_textInfo">
							<s:if test="text.length()>6">
								<s:property value="text.substring(0,6)+'...'" />
							</s:if>
							<s:elseif test="text.length()<7">
								<s:property value="text" />
							</s:elseif>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</s:iterator>
</s:if>

3、当出现list中嵌套list(set)等时,处理如下(Company类中包含Set<Classes> classes集合):

      <s:if test="#status.index<4">显示前四条记录。

<s:if test="companies != null">
	<s:iterator value="companies" id="company">
		<tr>
			<td height="59">
				<table cellpadding="0" cellspacing="0" border="0" width="337"
					style="float: right">
					<tr>
						<td height="30" class="company_name">
							${company.name }
						</td>
					</tr>
					<tr>
						<td height="29" class="company_keyword">
							<s:iterator value="classes" status="status">
								<s:if test="#status.index<4">
									<a href="#">${name }</a>
								</s:if>
							</s:iterator>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</s:iterator>
</s:if>

  4、<s:select/>标签的使用方法:

<s:select name="selectName" id="selectId" list="area" listKey="id" listValue="name" headerKey="0" headerValue="--请选择--"/>

 name:下拉框的名字、id:下拉框的id、list:后台传的l集合(lsit、set等)名字、listKey:<option value="">text</option>中的value值,listValue:<option>中的text值、headerKey:缺省的value值,headerValue:缺省的text值(即<option value="0">--请选择--</option>形式

5、<s:hidden>标签注意事项,赋值时应注意用以下形式:

<s:hidden name="nbrTypeCode" value="%{#request.oneTypeMap.typeName}"/>

 6、<s:if>标签使用的注意事项(判断与某个字符串相等时)如下:

<s:if test="nbrResource.nbrTypeCode==\"0\"">

7、struts2的result类型:

<result name="topic" type="redirect">/topicAction!findTopics.do?topicId=${topicId}&amp; elementId=${elementId}</result>

猜你喜欢

转载自lewis-fxb.iteye.com/blog/1168257