期末考试题解8
Fen
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.pojo.Report;
import com.QixunQiu.service.ReportService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/Fen")
public class Fen extends HttpServlet {
private ReportService reportService = new ReportService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int id = Integer.parseInt(request.getParameter("id"));
Report report=reportService.selectID(id);
String dailyscore=request.getParameter("dailyscore");
String Statereason=request.getParameter("Statereason");
request.setAttribute("dailyscore",dailyscore);
request.setAttribute("Statereason",Statereason);
reportService.Fen(report);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
toFen
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.pojo.Report;
import com.QixunQiu.service.ReportService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/toFen")
public class toFen extends HttpServlet {
private ReportService reportService = new ReportService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int ID = Integer.parseInt(request.getParameter("id"));
Report report= reportService.selectID(ID);
HttpSession session = request.getSession();
session.setAttribute("report", report);
request.getRequestDispatcher("/fen.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
fen.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改报告</title>
</head>
<body>
<h2>修改报告</h2>
<form action="${pageContext.request.contextPath}/Fen" method="post">
<%--隐藏域,提交id--%>
<input type="hidden" name="id" value="${report.getID()}">
<label for="dailyscore">分数:</label><br>
<input type="number" id="dailyscore" name="dailyscore"><br>
<label for="Statereason">内容:</label><br>
<input type="text" id="Statereason" name="Statereason" required><br>
<div class="buttons">
<input value="修改报告" type="submit" id="add_btn">
</div>
<br class="clear">
</form>
</body>
</html>
SelectAllUser
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.pojo.User;
import com.QixunQiu.service.UserService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
@WebServlet("/SelectAllUser")
public class SelectAllUser extends HttpServlet {
private UserService userService = new UserService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
List<User> users = userService.selectAllUser();
HttpSession session = request.getSession();
session.setAttribute("user", users);
request.getRequestDispatcher("/printfUser.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
printfUser.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function Back() {
window.location.href = "index.jsp";
}
</script>
</head>
<body>
<hr>
<table border="1" cellspacing="0" width="80%">
<tr>
<th>序号</th>
<th>用户ID</th>
<th>用户名</th>
<th>密码</th>
<th>操作</th>
</tr>
<c:forEach items="${user}" var="user" varStatus="status">
<tr align="center">
<td>${status.count}</td>
<td>${user.getUserID()}</td>
<td>${user.getUsername()}</td>
<td>${user.getPassword()}</td>
<td><a href="${pageContext.request.contextPath}/rePasswordServlet?UserID=${user.getUserID()}">重置密码</a>
<a href="${pageContext.request.contextPath}/deleteUserServlet?UserID=${user.getUserID()}">删除</a>
</td>
</tr>
</c:forEach>
</table>
<button onclick="Back()">返回首页</button>
</body>
</html>
SelectUser.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>查询用户</title>
</head>
<body>
<h2>查询课程</h2>
<form id="search-form" action="${pageContext.request.contextPath}/SelectByUserIDServlet" method="post">
ID:<input name="UserID" type="text" id="UserID" ><br>
<div class="buttons">
<input value="查询课程" type="submit" id="add_btn">
</div>
<br class="clear">
</form>
</body>
</html>
deleteUserServlet
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.service.UserService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/deleteUserServlet")
public class deleteUserServlet extends HttpServlet {
private UserService Userservice= new UserService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String UserID = request.getParameter("UserID");
Userservice.deleteUser(UserID);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能