parent
caaffd9418
commit
bcc5a549d5
@ -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<PostCheck> 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) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue