编写机房预约页面(reservation .jsp),该页面能够显示所有的机房预约信息,预约界面应该以表格的形式展示每个机房哪些时间段可选,哪些时间段已被哪位教师占用;同时管理员可以在该页面上完成预约登记操作,登记信息包括:教师、机房、时间段。
时间: 2024-05-04 16:20:24 浏览: 27
以下是一个简单的机房预约页面的实现,使用JSP和Servlet技术:
reservation.jsp
```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>机房预约</title>
</head>
<body>
<h1>机房预约</h1>
<table border="1">
<tr>
<th>机房</th>
<th>时间段1</th>
<th>时间段2</th>
<th>时间段3</th>
</tr>
<tr>
<td>机房1</td>
<td><a href="reserve?room=1&time=1">可预约</a></td>
<td>已占用(教师A)</td>
<td><a href="reserve?room=1&time=3">可预约</a></td>
</tr>
<tr>
<td>机房2</td>
<td><a href="reserve?room=2&time=1">可预约</a></td>
<td><a href="reserve?room=2&time=2">可预约</a></td>
<td>已占用(教师B)</td>
</tr>
</table>
<hr>
<h2>预约登记</h2>
<form action="reserve" method="post">
<label>机房:</label>
<select name="room">
<option value="1">机房1</option>
<option value="2">机房2</option>
</select>
<br>
<label>时间段:</label>
<select name="time">
<option value="1">时间段1</option>
<option value="2">时间段2</option>
<option value="3">时间段3</option>
</select>
<br>
<label>教师:</label>
<input type="text" name="teacher">
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
在页面中,我们使用表格展示了每个机房的可预约情况,同时提供了预约登记的表单。
当用户单击“可预约”链接时,会跳转到reserve servlet的URL,并在URL参数中传递机房编号和时间段编号,如:reserve?room=1&time=1。下面是reserve servlet的实现:
ReserveServlet.java
```java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ReserveServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int room = Integer.parseInt(request.getParameter("room"));
int time = Integer.parseInt(request.getParameter("time"));
// TODO: 根据机房和时间段查询是否已经被占用
// 如果未被占用,则跳转到预约确认页面
// 如果已经被占用,则跳转回预约页面,并显示错误信息
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int room = Integer.parseInt(request.getParameter("room"));
int time = Integer.parseInt(request.getParameter("time"));
String teacher = request.getParameter("teacher");
// TODO: 进行预约登记
// 如果预约成功,则跳转回预约页面,并显示成功信息
// 如果预约失败,则跳转回预约页面,并显示错误信息
}
}
```
在doGet()方法中,我们根据请求中的机房和时间段参数查询是否已经被占用。如果未被占用,则跳转到预约确认页面;如果已经被占用,则跳转回预约页面,并显示错误信息。
在doPost()方法中,我们获取表单中的机房、时间段和教师信息,进行预约登记。如果预约成功,则跳转回预约页面,并显示成功信息;如果预约失败,则跳转回预约页面,并显示错误信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)