如果机票数组为tickets,ticket的定义如下:package search; import java.util.Date; public class ticket { private int id; private String number; private String wherestart; private String gotowhere; private Date start_time; private Date end_time; private int counts; private double price; private Date order_time; public void setId(int id) { this.id=id; } public int getId() { return id; } public void setNumber(String number) { this.number=number; } public String getNumber() { return number; } public void setWherestart(String wherestart) { this.wherestart=wherestart; } public String getWherestart() { return wherestart; } public void setGotowhere(String gotowhere) { this.gotowhere=gotowhere; } public String getGotowhere() { return gotowhere; } public void setStart_time(Date start_time) { this.start_time=start_time; } public Date getStart_time() { return start_time; } public void setEnd_time(Date end_time) { this.end_time=end_time; } public Date getEnd_time() { return end_time; } public void setAirEnterPrice(double AirEnterPrice) { this.price=AirEnterPrice; } public double getAirEnterPrice() { return price; } public void setCounts(int counts) { this.counts=counts; } public int getCounts() { return counts; } public void setOrder_time(Date order_time) { this.order_time=order_time; } public Date getOrder_time() { return order_time; } },那么该如何修改上述界面代码
时间: 2024-02-18 13:59:49 浏览: 115
osticket-archive:一个实用程序,用于将超过一定期限的所有已关闭的票证归档到磁盘(包括附件),并将其从数据库中删除。 票证已存档为JSON文件
可以按照以下步骤修改上述界面代码:
1. 将 JSP 页面中的 `${ticketList}` 替换成 `${tickets}`,以对应机票数组的名称。
2. 在 JSP 页面中添加以下 JSTL 标签库:
```
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
```
3. 修改 JSTL 标签库中的 `<c:forEach>` 标签,以遍历机票数组:
```
<c:forEach var="ticket" items="${tickets}">
<tr>
<td>${ticket.id}</td>
<td>${ticket.start_time}</td>
<td>${ticket.end_time}</td>
<td>${ticket.wherestart}</td>
<td>${ticket.gotowhere}</td>
<td>${ticket.price}</td>
<td><input type="checkbox" name="selectedTickets" value="${ticket.id}"></td>
</tr>
</c:forEach>
```
4. 根据机票类的属性名在 JSP 页面中对应显示机票的信息,例如 `${ticket.id}` 对应机票的编号,`${ticket.start_time}` 对应机票的起飞时间,以此类推。
5. 在 JSP 页面的表单中,将购买机票的处理接口 `buyTicket` 改为处理 `selectedTickets` 参数的接口。
修改后的代码如下:
```
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>机票购买</title>
</head>
<body>
<h1>机票选择</h1>
<form action="buySelectedTickets" method="post">
<table>
<thead>
<tr>
<th>机票编号</th>
<th>起飞时间</th>
<th>到达时间</th>
<th>起飞地点</th>
<th>到达地点</th>
<th>价格</th>
<th>选择</th>
</tr>
</thead>
<tbody>
<c:forEach var="ticket" items="${tickets}">
<tr>
<td>${ticket.id}</td>
<td>${ticket.start_time}</td>
<td>${ticket.end_time}</td>
<td>${ticket.wherestart}</td>
<td>${ticket.gotowhere}</td>
<td>${ticket.price}</td>
<td><input type="checkbox" name="selectedTickets" value="${ticket.id}"></td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="购买">
</form>
</body>
</html>
```
阅读全文