struts form标签 <s:form action="login_sub.action" method="post" theme="simple"> </s:form> 普通文本框 <s:textfield name="userBean.userId"/> 密码文本框 <s:password name="userBean.password"/> 单选按钮, listSexBean集合类型,listKey及listValue取集合类型中每个对象的属性。listKey是传递到后台的键值,listValue是显示在前台的值 name是接受传递值的属性 <s:radio name="userBean.sex" list="lstSexBean" listKey="sexId" listValue="sexValue"></s:radio> 下拉列表 headKey以及headerValue是默认的选择项 <s:select name="userBean.city" list="lstCityBean" listKey="cityId" listValue="cityValue" headerKey="0" headerValue="--请选择--"></s:select> 多选框 <s:checkboxlist name="userBean.hobby" list="lstHobbyBean" listKey="hobbyId" listValue="hobbyValue"></s:checkboxlist> 提交 <s:submit value="提交"/> 重置 <s:reset value="重置"/> Iterator遍历器 <s:iterator value="{'aaa','bbb','ccc'}" var="x" status="status"> <s:property value="#x.toUpperCase()"/> 遍历过的元素总数:<s:property value="#status.count"></s:property><br> 遍历过的元素索引:<s:property value="#status.index"></s:property><br> 当前是否是偶数:<s:property value="#status.even"></s:property><br> 当前是否是奇数:<s:property value="#status.odd"></s:property><br> 是第一个元素么:<s:property value="#status.first"></s:property><br> 是最后一个元素么:<s:property value="#status.last"></s:property><br> </s:iterator> 遍历Map集合 <s:iterator value="#{1:'a',2:'b',3:'c'}"> <s:property value='key'/>|<s:property value='value'/> </s:iterator> <!-- 遍历Map集合元素 --> <s:iterator value="#{1:'a',2:'b',3:'c'}" var="x"> <s:property value='#x.key'/>|<s:property value='#x.value'/> </s:iterator> if else标签 <s:set var="age" value="19"></s:set> <s:if test="#age < 0 ">wrong age</s:if> <s:elseif test="#age < 20">too young</s:elseif> <s:else>yeah!</s:else> struts include 标签尽量少用,中文字符有时候存在问题.可以考虑使用jsp的include <s:include value="/_include1.html"/> Struts2 样式主题 simple xhtml(默认) css_xhtml ajax 建议使用simple标签 修改默认主题: 在Struts.xml中添加以下内容 <constant name="struts.ui.theme" value="simple"/> 如何定义自己的theme 1.css (覆盖struts2原来的css) 2.覆盖单个文件 3.定义自己的theme 4.实战 把所有主题定义为simple filederror特殊处理 自己控制其他标签的展现 如何修改jsp文件的默认打开方式 Windows->Preferences->File Associations->*.jsp->MyEclipse JSP Editor
Struts2 标签使用
猜你喜欢
转载自yangeoo.iteye.com/blog/2196857
今日推荐
周排行