struts标签中<s:iterator>的使用
2012-05-20 22:19
561 查看
struts中的Iterator标记实现迭代控制,它主要有三个参数value,id,status
value的值表示原始的数组或集合,id的值为当前迭代变量,status的值表示当前迭代的状态变量
使用的实例如下:
有实体类:
//路线
public class Path{
private Integer id; //记录编号
private Integer pathNum; //线路序号
private String pathName; //景点名称
private String introduce; //景点介绍
private Integer price; //价格
private String servicePhone; //客服热线
private String picture; //照片的路径
}
PathAction类:
//旅游路线
public class PathAction extends ActionSupport{
PathServiceImpl pathService;
private List<Path> pathList1 = new ArrayList();
private List<Path> pathList2 = new ArrayList();
private Integer pathId;
private Path myPath;
//获得路线一
public String getPath1(){
this.pathList1 = pathService.getPathByNum(1);
return "path1";
}
//获得路线二
public String getPath2(){
this.pathList2 = pathService.getPathByNum(2);
return "path2";
}
//获得某个景点的详细信息
public String description(){
this.myPath = pathService.getPathById(pathId);
return "descript";
}
public PathServiceImpl getPathService() {
return pathService;
}
public void setPathService(PathServiceImpl pathService) {
this.pathService = pathService;
}
public List<Path> getPathList1() {
return pathList1;
}
public List<Path> getPathList2() {
return pathList2;
}
public void setPathList1(List<Path> pathList1) {
this.pathList1 = pathList1;
}
public void setPathList2(List<Path> pathList2) {
this.pathList2 = pathList2;
}
public Integer getPathId() {
return pathId;
}
public void setPathId(Integer pathId) {
this.pathId = pathId;
}
public Path getMyPath() {
return myPath;
}
public void setMyPath(Path myPath) {
this.myPath = myPath;
}
}
jsp中展示表格的代码:
<table border="1" width="550">
<tr>
<td width="10%" align="center" height="16">序号</td>
<td width="20%" align="center" height="16">名称</td>
<td width="20%" align="center" height="16">价格(元)</td>
<td width="30%" align="center" height="16">客服热线</td>
<td width="10%" align="center" height="16">详情</td>
<td width="10%" align="center" height="16">预订</td>
</tr>
<%int cnt = 1; %>
<s:iterator value="pathList1" id="pt1" status="st1">
<tr>
<td width="10%" align="center" height="16"><%=cnt++ %></td>
<td width="20%" align="center" height="16">${pt1.pathName}</td>
<td width="20%" align="center" height="16">${pt1.price}</td>
<td width="30%" align="center" height="16">${pt1.servicePhone}</td>
<td width="10%" align="center" height="16">
<A class=nav href="path_description.action?pathId=${pt1.id}">查看</A></td>
<td width="10%" align="center" height="16">
<A class=nav href="order_detail.action?pathId=${pt1.id}&userId=<%=session.getAttribute("userId")%>">预订</A></td>
</tr>
</s:iterator>
</table>
struts.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.devMode" value="true"/>
<package name="default" extends="struts-default,jasperreports-default" namespace="/">
<action name="path_*" class="pathAction" method="{1}">
<result name="path1">num1.jsp</result>
</action>
</package>
</struts>
访问path_getPath1.action即可得到路线一的列表。
value的值表示原始的数组或集合,id的值为当前迭代变量,status的值表示当前迭代的状态变量
使用的实例如下:
有实体类:
//路线
public class Path{
private Integer id; //记录编号
private Integer pathNum; //线路序号
private String pathName; //景点名称
private String introduce; //景点介绍
private Integer price; //价格
private String servicePhone; //客服热线
private String picture; //照片的路径
}
PathAction类:
//旅游路线
public class PathAction extends ActionSupport{
PathServiceImpl pathService;
private List<Path> pathList1 = new ArrayList();
private List<Path> pathList2 = new ArrayList();
private Integer pathId;
private Path myPath;
//获得路线一
public String getPath1(){
this.pathList1 = pathService.getPathByNum(1);
return "path1";
}
//获得路线二
public String getPath2(){
this.pathList2 = pathService.getPathByNum(2);
return "path2";
}
//获得某个景点的详细信息
public String description(){
this.myPath = pathService.getPathById(pathId);
return "descript";
}
public PathServiceImpl getPathService() {
return pathService;
}
public void setPathService(PathServiceImpl pathService) {
this.pathService = pathService;
}
public List<Path> getPathList1() {
return pathList1;
}
public List<Path> getPathList2() {
return pathList2;
}
public void setPathList1(List<Path> pathList1) {
this.pathList1 = pathList1;
}
public void setPathList2(List<Path> pathList2) {
this.pathList2 = pathList2;
}
public Integer getPathId() {
return pathId;
}
public void setPathId(Integer pathId) {
this.pathId = pathId;
}
public Path getMyPath() {
return myPath;
}
public void setMyPath(Path myPath) {
this.myPath = myPath;
}
}
jsp中展示表格的代码:
<table border="1" width="550">
<tr>
<td width="10%" align="center" height="16">序号</td>
<td width="20%" align="center" height="16">名称</td>
<td width="20%" align="center" height="16">价格(元)</td>
<td width="30%" align="center" height="16">客服热线</td>
<td width="10%" align="center" height="16">详情</td>
<td width="10%" align="center" height="16">预订</td>
</tr>
<%int cnt = 1; %>
<s:iterator value="pathList1" id="pt1" status="st1">
<tr>
<td width="10%" align="center" height="16"><%=cnt++ %></td>
<td width="20%" align="center" height="16">${pt1.pathName}</td>
<td width="20%" align="center" height="16">${pt1.price}</td>
<td width="30%" align="center" height="16">${pt1.servicePhone}</td>
<td width="10%" align="center" height="16">
<A class=nav href="path_description.action?pathId=${pt1.id}">查看</A></td>
<td width="10%" align="center" height="16">
<A class=nav href="order_detail.action?pathId=${pt1.id}&userId=<%=session.getAttribute("userId")%>">预订</A></td>
</tr>
</s:iterator>
</table>
struts.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.devMode" value="true"/>
<package name="default" extends="struts-default,jasperreports-default" namespace="/">
<action name="path_*" class="pathAction" method="{1}">
<result name="path1">num1.jsp</result>
</action>
</package>
</struts>
访问path_getPath1.action即可得到路线一的列表。
相关文章推荐
- Struts标签<s:action>的使用详解
- Struts遍历标签<s:iterator>总结
- struts标签<s:date>的使用
- Struts2中<s-if>和<s-iterator>标签的使用
- Struts标签-使用<s:iterator>迭代遍历集合中的集合
- Struts2中<s-if>和<s-iterator>标签的使用
- struts学习笔记 [JSTL]<c:forEach>标签的使用
- Struts2中<s:iterator></s:iterator>标签的使用:
- struts与jsp <s:iterator>使用方法
- Struts中<logic:present><logic:iterator>的使用
- Struts2中<s-if>和<s-iterator>标签的使用
- Struts2<s:iterator value="" var="lst">中var的使用和一些标签的使用体会
- Struts2标签<s:iterator>中使用Map
- Struts2中<s-if>和<s-iterator>标签的使用
- Struts2中<s-if>和<s-iterator>标签的使用
- Struts2中<s-if>和<s-iterator>标签的使用
- 在使用struts标签时,把<s:if>中的test写成了text
- 使用<s:iterator>标签来循环遍历某一实体下的set集合数据
- xjh struts标签版本比较老的,<s:iterator >没有var属性的嵌套循环 使用<s:property value='#id.xxx'>
- Struts标签-使用<s:iterator>标签遍历集合