使用jsp写一个校园失物招领系统
时间: 2024-05-04 09:22:34 浏览: 28
这是一个简单的校园失物招领系统的JSP代码示例,包括前端页面和后端代码。
前端页面:
```html
<!DOCTYPE html>
<html>
<head>
<title>校园失物招领系统</title>
</head>
<body>
<h2>校园失物招领系统</h2>
<form action="LostFoundServlet" method="post">
<label for="type">类型:</label>
<select name="type" id="type">
<option value="0">失物</option>
<option value="1">招领</option>
</select><br><br>
<label for="name">物品名称:</label>
<input type="text" name="name" id="name"><br><br>
<label for="description">详细描述:</label>
<textarea name="description" id="description"></textarea><br><br>
<label for="contact">联系方式:</label>
<input type="text" name="contact" id="contact"><br><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
后端代码:
```java
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LostFoundServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ArrayList<Item> lostItems = new ArrayList<Item>();
private ArrayList<Item> foundItems = new ArrayList<Item>();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String type = request.getParameter("type");
String name = request.getParameter("name");
String description = request.getParameter("description");
String contact = request.getParameter("contact");
if(type.equals("0")) {
lostItems.add(new Item(name, description, contact));
out.println("<p>失物信息已提交!</p>");
} else if(type.equals("1")) {
foundItems.add(new Item(name, description, contact));
out.println("<p>招领信息已提交!</p>");
} else {
out.println("<p>类型错误!</p>");
}
}
class Item {
String name;
String description;
String contact;
public Item(String name, String description, String contact) {
this.name = name;
this.description = description;
this.contact = contact;
}
}
}
```
注意:这个示例只是一个简单的演示,实际的校园失物招领系统需要更加完善的功能,如查询、管理等。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)