struts标签中<s:iterator>的使用

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即可得到路线一的列表。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值