layout: post
title: struts2标签
subtitle: struts2标签
date: 2018-06-03
author: ZL
header-img: img/20180603.jpg
catalog: true
tags:
- struts标签
标签结构
image控制标签
s:iterator
s:iterator遍历
list数据准备
@Override
public String execute() throws Exception {
List<String> list = new ArrayList<String>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ddd");
ActionContext.getContext().put("list", list);
this.addActionError("error!!!!");
return SUCCESS;
}
iterator遍历list
<s:iterator value="#list">
<s:property/>
</s:iterator>
<br>
<s:iterator value="#list" var="name">
<s:property value="#name"/>
</s:iterator>
<br>
效果
aaa bbb ccc ddd
aaa bbb ccc ddd
s:iterator计数
<s:iterator begin="1" end="100" step="1">
<s:property/>
</s:iterator>
<br>
效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
if,elseif,else
<s:if test="#list.size() == 4">
list.size = 4;
</s:if>
<s:elseif test="#list.size() == 3">
list.size = 3;
</s:elseif>
<s:else>
list 不3不4
</s:else>
效果
list.size = 4;
数据标签
s:property
结合OGNL取数据
<s:property value="#list.size()"/>
效果
4
UI标签
表单标签
<!-- struts2表单标签 -->
<!-- 好处1: 内置了一套样式. -->
<!-- 好处2: 自动回显,根据栈中的属性 -->
<!-- theme:指定表单的主题
xhtml:默认
simple:没有主题
-->
<s:form action="Demo3Action" namespace="/" theme="xhtml" >
<s:textfield name="name" label="用户名" ></s:textfield>
<s:password name="password" label="密码" ></s:password>
<s:radio list="{'男','女'}" name="gender" label="性别" ></s:radio>
<s:radio list="#{1:'男',0:'女'}" name="gender" label="性别" ></s:radio>
<s:checkboxlist list="#{2:'抽烟',1:'喝酒',0:'烫头'}" name="habits" label="爱好" ></s:checkboxlist>
<s:select list="#{2:'大专',1:'本科',0:'硕士'}" headerKey="" headerValue="---请选择---" name="edu" label="学历" >
</s:select>
<s:file name="photo" label="近照" ></s:file>
<s:textarea name="desc" label="个人简介" ></s:textarea>
<s:submit value="提交" ></s:submit>
</s:form>
image效果
非表单标签s:actionerror
在Action中this.addActionError("");
@Override
public String execute() throws Exception {
List<String> list = new ArrayList<String>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ddd");
ActionContext.getContext().put("list", list);
this.addActionError("error!!!!");
return SUCCESS;
}
在jsp中<s:actionerror/>即可
<s:actionerror/>
image在网页上
网友评论