From 2a60bdb98fef9a3863e5ccf32535064243c42a62 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9C=E5=BE=90=E7=AB=8B=E5=9F=8E=E2=80=9D?=
<“897185960@qq.com”>
Date: Sun, 28 May 2023 21:20:39 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...56\346\224\271\344\275\234\344\270\232.md" | 243 ++++++++++++++++
...56\346\224\271\344\275\234\344\270\232.md" | 262 ++++++++++++++++++
.../import javax.md" | 2 -
3 files changed, 505 insertions(+), 2 deletions(-)
create mode 100644 "11 \345\276\220\347\253\213\345\237\216/20230528 \345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
create mode 100644 "11 \345\276\220\347\253\213\345\237\216/20230528 \347\275\221\351\241\265\345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
diff --git "a/11 \345\276\220\347\253\213\345\237\216/20230528 \345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md" "b/11 \345\276\220\347\253\213\345\237\216/20230528 \345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
new file mode 100644
index 0000000..f8aabe9
--- /dev/null
+++ "b/11 \345\276\220\347\253\213\345\237\216/20230528 \345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
@@ -0,0 +1,243 @@
+```java
+<%@ page import="javax.xml.transform.Result" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="test.Tool" %><%--
+ Created by IntelliJ IDEA.
+ User: Administrator
+ Date: 2023-05-27
+ Time: 15:29
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 学生列表
+
+
+
+ 学号 | 姓名 | 性别 | 操作 |
+ <%
+ String url = "select * from student";
+ ResultSet res = Tool.select(url);
+ while (res.next()){
+ int id = res.getInt("id");
+ String name = res.getString("name");
+ String sex = res.getString("sex");
+ %>
+
+
+ <%=id%>
+ |
+ <%=name%> |
+ <%=sex%> |
+ 删除 修改 |
+
+ <%
+ }
+ %>
+
+
+
+
+```
+
+```Java
+package test;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.*;
+import java.io.IOException;
+import java.sql.SQLException;
+
+@WebServlet(name = "deleteById", value = "/deleteById")
+public class Servlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ String id = req.getParameter("id");
+ String sql = "delete from student where id = ?";
+ try {
+ int i = Tool.DDL(sql,id);
+ if (i>0){
+ System.out.println("删除成功");
+ resp.getWriter().write("");
+ }
+ else {
+ System.out.println("删除失败");
+ resp.getWriter().write("删除失败");
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+}
+
+```
+
+```java
+package test;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+@WebServlet(name = "update" ,value = "/updateById")
+public class ServletUp extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ try {
+ //获取信息
+ String id = req.getParameter("id");
+ String select = "select * from student where id = ?";
+ ResultSet res = Tool.select(select,id);
+ res.next();
+ String oldID = res.getString("id");
+ String oldName= res.getString("name");
+ String oldSex = res.getString("sex");
+ Student stu = new Student(oldID,oldName,oldSex);
+ req.setAttribute("student",stu);
+ req.getRequestDispatcher("/Update.jsp").forward(req,resp);
+ }
+ catch (SQLException e){
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+}
+
+```
+
+```jsp
+<%@ page import="test.Student" %><%--
+ Created by IntelliJ IDEA.
+ User: Administrator
+ Date: 2023-05-28
+ Time: 19:28
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 修改
+
+
+ <%Student student = (Student)request.getAttribute("student");
+ %>
+ <%student.getId();%>
+
+
+
+
+```
+
+```java
+package test;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.sql.SQLException;
+
+@WebServlet(name = "ServletUpdate",value = "/ServletUpdate")
+public class ServletUpdate extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ String id = req.getParameter("id");
+ String name = req.getParameter("name");
+ String sex = req.getParameter("sex");
+ String sql = "update student set name = ?,sex = ? where id = ?";
+ try {
+ int i = Tool.DDL(sql,name,sex,id);
+ if (i>0){
+ System.out.println("修改成功");
+ resp.getWriter().write("");
+ }
+ else {
+ System.out.println("修改失败");
+ resp.getWriter().write("修改失败");
+ }
+
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+
+```
+
+```java
+package test;
+
+public class Student {
+ String id;
+ String name;
+ String sex;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String 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;
+ }
+
+ public Student(String id, String name, String sex) {
+ this.id = id;
+ this.name = name;
+ this.sex = sex;
+ }
+}
+
+```
+
diff --git "a/11 \345\276\220\347\253\213\345\237\216/20230528 \347\275\221\351\241\265\345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md" "b/11 \345\276\220\347\253\213\345\237\216/20230528 \347\275\221\351\241\265\345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
new file mode 100644
index 0000000..8fc73d1
--- /dev/null
+++ "b/11 \345\276\220\347\253\213\345\237\216/20230528 \347\275\221\351\241\265\345\210\240\351\231\244\344\277\256\346\224\271\344\275\234\344\270\232.md"
@@ -0,0 +1,262 @@
+```java
+// 初始网页
+<%@ page import="javax.xml.transform.Result" %>
+<%@ page import="java.sql.ResultSet" %>
+<%@ page import="test.Tool" %><%--
+ Created by IntelliJ IDEA.
+ User: Administrator
+ Date: 2023-05-27
+ Time: 15:29
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 学生列表
+
+
+
+
+
+ 学号
+ |
+
+ 姓名
+ |
+
+ 性别
+ |
+
+ 操作
+ |
+
+ <%
+ String url = "select * from student";
+ ResultSet res = Tool.select(url);
+ while (res.next()){
+ int id = res.getInt("id");
+ String name = res.getString("name");
+ String sex = res.getString("sex");
+ %>
+
+
+ <%=id%>
+ |
+ <%=name%> |
+ <%=sex%> |
+ 删除 修改 |
+
+ <%
+ }
+ %>
+
+
+
+
+```
+
+```Java
+// 删除
+package test;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+import javax.servlet.annotation.*;
+import java.io.IOException;
+import java.sql.SQLException;
+
+@WebServlet(name = "deleteById", value = "/deleteById")
+public class Servlet extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ String id = req.getParameter("id");
+ String sql = "delete from student where id = ?";
+ try {
+ int i = Tool.DDL(sql,id);
+ if (i>0){
+ System.out.println("删除成功");
+ resp.getWriter().write("");
+ }
+ else {
+ System.out.println("删除失败");
+ resp.getWriter().write("删除失败");
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ }
+}
+
+```
+
+```java
+//修改数据
+package test;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+@WebServlet(name = "update" ,value = "/updateById")
+public class ServletUp extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ try {
+ //获取信息
+ String id = req.getParameter("id");
+ String select = "select * from student where id = ?";
+ ResultSet res = Tool.select(select,id);
+ res.next();
+ String oldID = res.getString("id");
+ String oldName= res.getString("name");
+ String oldSex = res.getString("sex");
+ Student stu = new Student(oldID,oldName,oldSex);
+ req.setAttribute("student",stu);
+ req.getRequestDispatcher("/Update.jsp").forward(req,resp);
+ }
+ catch (SQLException e){
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+}
+
+```
+
+```jsp
+//修改网页
+<%@ page import="test.Student" %><%--
+ Created by IntelliJ IDEA.
+ User: Administrator
+ Date: 2023-05-28
+ Time: 19:28
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ 修改
+
+
+ <%Student student = (Student)request.getAttribute("student");
+ %>
+ <%student.getId();%>
+
+
+
+
+```
+
+```java
+// 修改运行
+package test;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.sql.SQLException;
+
+@WebServlet(name = "ServletUpdate",value = "/ServletUpdate")
+public class ServletUpdate extends HttpServlet {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setContentType("text/html;charset=utf-8");
+ String id = req.getParameter("id");
+ String name = req.getParameter("name");
+ String sex = req.getParameter("sex");
+ String sql = "update student set name = ?,sex = ? where id = ?";
+ try {
+ int i = Tool.DDL(sql,name,sex,id);
+ if (i>0){
+ System.out.println("修改成功");
+ resp.getWriter().write("");
+ }
+ else {
+ System.out.println("修改失败");
+ resp.getWriter().write("修改失败");
+ }
+
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+
+```
+
+```java
+// 学生类
+package test;
+
+public class Student {
+ String id;
+ String name;
+ String sex;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String 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;
+ }
+
+ public Student(String id, String name, String sex) {
+ this.id = id;
+ this.name = name;
+ this.sex = sex;
+ }
+}
+
+```
+
diff --git "a/11 \345\276\220\347\253\213\345\237\216/import javax.md" "b/11 \345\276\220\347\253\213\345\237\216/import javax.md"
index 1fa6c5a..6db0c44 100644
--- "a/11 \345\276\220\347\253\213\345\237\216/import javax.md"
+++ "b/11 \345\276\220\347\253\213\345\237\216/import javax.md"
@@ -148,7 +148,5 @@ public class DBUtil {