Day8
今日完成了删除和修改的功能。
upPage修改成绩页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>修改界面</title> </head> <style> #a{ width: 70%; height: 600px; background-color: lemonchiffon; margin-left: 240px; margin-top: 50px; position: absolute; } #b{ margin-left: 300px; margin-top: 100px; } input{ margin-top: 15px; margin-left: 70px; font-size: 30px; color: red; font-family: 华文新魏; } button{ background-color: azure; width: 100px; height: 25px; font-family: 华文新魏; margin-left: 110px; } span{ margin-left: 100px; color: red; } </style> <script> function goMainPage(){ window.location.href = "goMainPage?admId=${admId}"; } function sureUp(){ let a = document.getElementById("a1").value; let b = document.getElementById("a2").value; let c = document.getElementById("a3").value; let d = document.getElementById("a4").value; window.location.href = "upStu?admid=${admId}&stuId=${stuId}&a="+a+"&b="+b+"&c="+c+"&d="+d; } </script> <body> <div id="a"> <div style="font-size: 40px;margin-top: 40px;margin-left: 70px">成绩修改界面</div> <span>学生: ${stuId}</span> <span>管理员: ${admId}</span> <div id="b"> 计算机网: <input type="text" id="a1"><br> <br> 软件工程: <input type="text" id="a2"><br> <br> 软件测试: <input type="text" id="a3"><br> <br> 机器学习: <input type="text" id="a4"><br> <br> <button onclick="goMainPage()">回主界面</button> <button onclick="sureUp()">确认修改</button> </div> </div> </body> </html>
Toup类
@WebServlet("/upTp")
public class ToUp extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String admId = req.getParameter("admId");
String stuId = req.getParameter("stuId");
req.setAttribute("admId",admId);
req.setAttribute("stuId",stuId);
req.getRequestDispatcher("upPage.jsp").forward(req,resp);
}
}
upPage 类
@WebServlet("/upStu")
public class upPage extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String admId = req.getParameter("admId");
String stuId = req.getParameter("stuId");
String a = req.getParameter("a");
String b = req.getParameter("b");
String c = req.getParameter("c");
String d = req.getParameter("d");
FileService fs = new FIleServiceImpl();
fs.upScore(stuId,a,b,c,d);
//管理员
User user= fs.getAdmine(admId);
ArrayList<User> arr = fs.getAllStudent();
req.setAttribute("user",user);
req.setAttribute("arr",arr);
req.getRequestDispatcher("mainPage.jsp").forward(req,resp);
}
}
FileDaoImpl中增加的部分
@Override public void del(String stu) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; String sql1 = "DELETE FROM u_user WHERE u_id="+stu; String sql2 = "DELETE FROM userchoose WHERE u_id="+stu; try { preparedStatement = connection.prepareStatement(sql1); preparedStatement.executeQuery(); preparedStatement = connection.prepareStatement(sql2); preparedStatement.executeQuery(); } catch (SQLException e) { e.printStackTrace(); } } @Override public void upScore(String stuId, String a, String b, String c, String d) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; int index = 0; String[] file = {a,b,c,d}; try { for (int i=1001;i<=1004;i++){ String sql = "UPDATE userchoose SET c_score="+ file[index]+" WHERE u_id="+stuId+" AND c_id="+i; index++; preparedStatement = connection.prepareStatement(sql); preparedStatement.executeQuery(); } } catch (SQLException e) { e.printStackTrace(); } }
FIleDao类
public interface FIleDao { ArrayList<User> getAllStudent(); User getFileByNameOrId(String v); User getAdmine(String id); ArrayList getPersonFile(String studentId); void del(String stu); void upScore(String stuId, String a, String b, String c, String d); }
FileService类
public interface FileService { ArrayList<User> getAllStudent(); User getFileByNameOrId(String v); User getAdmine(String id); ArrayList getPersonFile(String studentId); void del(String stu); void upScore(String stuId, String a, String b, String c, String d); }
FileServiceImpl类
public class FIleServiceImpl implements FileService { FIleDao fs = new FileDaoImpl(); @Override public ArrayList<User> getAllStudent() { // 访问持久层 FIleDao fs = new FileDaoImpl(); return fs.getAllStudent(); } @Override public User getFileByNameOrId(String v) { FIleDao fd = new FileDaoImpl(); return fd.getFileByNameOrId(v); } @Override public User getAdmine(String id) { return fs.getAdmine(id); } @Override public ArrayList getPersonFile(String studentId) { return fs.getPersonFile(studentId); } @Override public void del(String stu) { fs.del(stu); } @Override public void upScore(String stuId, String a, String b, String c, String d) { fs.upScore(stuId,a,b,c,d); } }
至此学生成绩系统完毕。

浙公网安备 33010602011771号