日期:2014-05-16  浏览次数:20298 次

struts2&jstl标签总结
引入STRUTS2标签库和JSTL标签库
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>



if 标签
<s:if test="#parameters['siteId']!=null">
</s:if>

因为JSTL没有else标签 所以比较好的方法是
<c:if var="current" test="${page.pageNo == i}">
${i}
</c:if>
<c:if test="${not current}">
</c:if>

action里有boolean属性
<s:if test="!emptySite"></s:if>

<c:if test="${emptySite}"></c:if>


select 标签
<s:select list="pageList" listKey="key" id="swpTplCata" listValue="value" name="pageId" />

pageList 对应action里的pageList属性 arrayList
listKey="key" listValue="value" 为固定写法
name="pageId" 为下拉框的默认值 pageId也是action里的属性 要提供get方法

radio 标签
<s:if test="checkedRoleIds.size() == 0">
<s:radio name="checkedRoleIds" list="allRoleList" listKey="id" listValue="desc" />
</s:if>
<s:else>
<s:radio name="checkedRoleIds" list="allRoleList" listKey="id" listValue="desc" value="checkedRoleIds[0]" />
</s:else>

value="checkedRoleIds[0]" 默认选中的值
private List<Long> checkedRoleIds; //用户角色

	public List<Long> getCheckedRoleIds() {
		return checkedRoleIds;
	}
	public void setCheckedRoleIds(List<Long> checkedRoleIds) {
		this.checkedRoleIds = checkedRoleIds;
	}


form 标签
<s:form method="post" action="%{#request.contextPath}/account/user!save"
	theme="simple" enctype="multipart/form-data" id="register_form"
	name="form">


iterator 标签
<s:iterator value="page.result">
</s:iterator>


jstl循环
<c:forEach var="i" begin="1" end="${page.totalPages}" step="1">
${i}
</c:forEach>


jstl循环map
<c:forEach items="${model}" var="model">
	${model.key}
	${model.value}
	<br />
</c:forEach>


自定义标签
http://dingbuoyi.iteye.com/admin/blogs/818950