From 1c8354c3dadaf6f8c5b5347654882976eb11ab79 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=83=A1=E6=99=BA=E7=A0=94?= <3058944672@qq.com>
Date: Sat, 3 Jun 2023 10:42:52 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...46\254\241\344\275\234\344\270\232.md.txt" | 256 ++++++++++++++++++
1 file changed, 256 insertions(+)
create mode 100644 "46 \350\203\241\346\231\272\347\240\224/20230603\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md.txt"
diff --git "a/46 \350\203\241\346\231\272\347\240\224/20230603\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md.txt" "b/46 \350\203\241\346\231\272\347\240\224/20230603\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md.txt"
new file mode 100644
index 0000000..6440e3e
--- /dev/null
+++ "b/46 \350\203\241\346\231\272\347\240\224/20230603\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232.md.txt"
@@ -0,0 +1,256 @@
+<%@ 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%> |
+ 修改 删除 |
+
+
+
+ <%
+ }
+ %>
+
+
+
+
+
+
+```
+
+```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;
+ }
+}
+
+```
+
+```java
+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 {
+
+ }
+}
+
+```
+
+```java
+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 {
+
+ }
+}
+
+```
+
+```java
+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);
+ }
+ }
+}
+
+```
+
+
+
+```jsp
+<%@ 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");
+%>
+
+
+
+
+```
\ No newline at end of file
--
Gitee