From 2630f109e4047aea7bbc8dfc5ef438c52c0a13d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=86=8A=E6=99=AF=E5=B3=B0?= <1532577707@qq.com>
Date: Sun, 28 May 2023 22:18:32 +0800
Subject: [PATCH] 0
---
.../20230528\344\275\234\344\270\232.md" | 244 ++++++++++++++++++
1 file changed, 244 insertions(+)
create mode 100644 "33 \347\206\212\346\231\257\345\263\260/20230528\344\275\234\344\270\232.md"
diff --git "a/33 \347\206\212\346\231\257\345\263\260/20230528\344\275\234\344\270\232.md" "b/33 \347\206\212\346\231\257\345\263\260/20230528\344\275\234\344\270\232.md"
new file mode 100644
index 0000000..6b48d91
--- /dev/null
+++ "b/33 \347\206\212\346\231\257\345\263\260/20230528\344\275\234\344\270\232.md"
@@ -0,0 +1,244 @@
+```html
+<%@ page import="Tool.DbJbdc" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 学生信息
+
+
+
+
+ | 编号 | 姓名 | 性别 | 操作 |
+ <%
+ String sql="select * from student";
+ ResultSet rs = DbJbdc.Query(sql);
+ while (rs.next()){
+ int id = rs.getInt("id");
+ String name = rs.getString("name");
+ String sex = rs.getString("sex");
+
+ %>
+
+ | <%=id%> |
+ <%=name%> |
+ <%=sex%> |
+ 修改 删除 |
+
+
+
+ <%
+ }
+ %>
+
+
+
+
+
+------------------------------------------------------------
+ <%@ page import="servlet.student" %><%--
+ Created by IntelliJ IDEA.
+ User: Administrator
+ Date: 2023-05-27
+ Time: 16:55
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 修改学生
+
+
+<%
+ student stu = (student) request.getAttribute("student");
+%>
+
+
+
+```
+
+
+
+```java
+package servlet;
+
+public class student {
+ private int id;
+ private String name;
+ private String sex;
+
+ public student() {
+ }
+
+ public student(int id, String name, String sex) {
+ this.id = id;
+ this.name = name;
+ this.sex = sex;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getSex() {
+ return sex;
+ }
+
+ public void setSex(String sex) {
+ this.sex = sex;
+ }
+}
+-----------------------------------------------------------
+ package servlet;
+
+import Tool.DbJbdc;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+
+@WebServlet(name = "updateById", value = "/updateById")
+public class updateById extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html;charset=utf-8");
+ request.setCharacterEncoding("utf-8");
+
+ String id = request.getParameter("id");
+ String sql ="select * from student where id=?";
+ try {
+ ResultSet rs = DbJbdc.Query(sql, id);
+ rs.next();
+ int id1 = rs.getInt("id");
+ String name = rs.getString("name");
+ String sex = rs.getString("sex");
+ student stu = new student(id1, name, sex);
+ request.setAttribute("student",stu);
+ request.getRequestDispatcher("/edit.jsp").forward(request,response);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+}
+---------------------------------------------------------
+ package servlet;
+
+import Tool.DbJbdc;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+
+@WebServlet(name = "deleteById", value = "/deleteById")
+public class deleteById extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html;charset=utf-8");
+ request.setCharacterEncoding("utf-8");
+ String id = request.getParameter("id");
+ String sql="delete from student where id=?";
+ try {
+ int i = DbJbdc.Update(sql, id);
+ if (i>0){
+ response.getWriter().write("");
+// response.sendRedirect("/index.jsp");
+ }else {
+ response.getWriter().write("删除失败");
+ }
+ } catch (SQLException | ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+}
+------------------------------------------------------------
+ package servlet;
+
+import Tool.DbJbdc;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.annotation.WebServlet;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+
+@WebServlet(name = "saveUpdate", value = "/saveUpdate")
+public class saveUpdate extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html;charset=utf-8");
+ request.setCharacterEncoding("utf-8");
+
+ String id = request.getParameter("id");
+ String name = request.getParameter("name");
+ String sex = request.getParameter("sex");
+
+ String sql ="update student set name=? , sex=? where id=?";
+ try {
+ int i = DbJbdc.Update(sql, name, sex,id);
+ if (i>0){
+ response.getWriter().write("");
+ // response.sendRedirect("/index.jsp");
+ }else {
+ response.getWriter().write("修改失败");
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+```
+
--
Gitee