From bcc5a549d53b18605b9f655d9a4751f7d1bdf3f3 Mon Sep 17 00:00:00 2001 From: p5cekhzoa <3257571545@qq.com> Date: Wed, 5 Jan 2022 23:59:45 +0800 Subject: [PATCH] ADD file via upload --- PostCheckServlet.java | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 PostCheckServlet.java diff --git a/PostCheckServlet.java b/PostCheckServlet.java new file mode 100644 index 0000000..bfed518 --- /dev/null +++ b/PostCheckServlet.java @@ -0,0 +1,98 @@ +package com.demo; + +import java.io.IOException; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.*; + +import javax.servlet.RequestDispatcher; +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 com.dao.PostCheckDao; +import com.dao.PostCheckDaoImpl; +import com.domain.PostCheck; + + +/** + * Servlet implementation class PostCheckServlet + */ +@WebServlet(name ="PostCheckServlet",urlPatterns={"/PostCheckServlet"}) +public class PostCheckServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + +// java.sql.Connection dbconn = null; public void init() { String driver = +// "com.mysql.jdbc.Driver"; String dburl = +// "jdbc:mysql://127.0.0.1:3306/xinxin?useSSL=true"; String username = "root"; +// String password = "zhao157"; try{ Class.forName(driver); // 加载驱动程序 // 创建连接对象 +// dbconn = DriverManager.getConnection(dburl,username,password); +// }catch(ClassNotFoundException e1){ System.out.println(e1); +// getServletContext().log("驱动程序类找不到!"); }catch(SQLException e2){ +// System.out.println(e2); } } + + + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doPost(request,response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + String action = request.getParameter("action"); + if(action!=null&&action.equals("remove")){ + removePostCheck(request,response); + } + else if (action.equals("list")){ + listPostCheck(request,response); + }else { + System.out.println("失败"); + } + + } + + private void listPostCheck(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ + // TODO Auto-generated method stub + + PostCheckDao dao = new PostCheckDaoImpl(); + try{ + System.out.println("是哦哟"); + List list= dao.listPostCheck(); + request.setAttribute("PostCheckList",list); + System.out.println(list+"test3"); + }catch(SQLException e) {} + RequestDispatcher rd = request.getRequestDispatcher("PostCheck.jsp"); + System.out.println("1212"); + rd.forward(request, response); + + } + + + private void removePostCheck(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ + // TODO Auto-generated method stub + int Dyid=Integer.parseInt(request.getParameter("Dyid")); + PostCheckDao dao=new PostCheckDaoImpl(); + try { + int success=dao.removePostCheck(Dyid); + if(success>0) { + listPostCheck(request,response); + } + }catch(SQLException e) {} + } + + + + + + +}