You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.7 KiB
114 lines
3.7 KiB
package com.demo;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
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.Dao;
|
|
import com.dao.DynamicDao;
|
|
import com.dao.DynamicDaoImpl;
|
|
import com.domain.Dynamic;
|
|
|
|
|
|
|
|
/**
|
|
* Servlet implementation class PostCheckServlet
|
|
*/
|
|
@WebServlet(name ="DynamicServlet",urlPatterns={"/Dynamic.do"})
|
|
public class DynamicServlet extends HttpServlet implements Dao {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
// public void init() {
|
|
// String driver = "com.mysql.cj.jdbc.Driver";
|
|
// String dburl = "jdbc:mysql://127.0.0.1:3306/tooth?useSSL=true";
|
|
// String username = "root";
|
|
// String password = "root";
|
|
// 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);
|
|
// }
|
|
// }
|
|
// 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)
|
|
*/
|
|
public void doGet(HttpServletRequest request,
|
|
HttpServletResponse response)
|
|
throws ServletException,IOException{
|
|
doPost(request,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")){
|
|
removeDynamic(request,response);
|
|
}
|
|
else if (action.equals("list")){
|
|
listDynamic(request,response);
|
|
}else {
|
|
System.out.println("失败");
|
|
}
|
|
|
|
}
|
|
|
|
private void listDynamic(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
|
// TODO Auto-generated method stub
|
|
|
|
DynamicDao dao = new DynamicDaoImpl();
|
|
try{
|
|
|
|
List<Dynamic> list= dao.listDynamic();
|
|
request.setAttribute("DynamicList",list);
|
|
|
|
}catch(SQLException e) {}
|
|
RequestDispatcher rd = request.getRequestDispatcher("da-dynamic.jsp");
|
|
|
|
rd.forward(request, response);
|
|
|
|
}
|
|
|
|
|
|
private void removeDynamic(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
|
// TODO Auto-generated method stub
|
|
int Dyid=Integer.parseInt(request.getParameter("Dyid"));
|
|
DynamicDao dao=new DynamicDaoImpl();
|
|
try {
|
|
int success=dao.removeDynamic(Dyid);
|
|
if(success>0) {
|
|
listDynamic(request,response);
|
|
}
|
|
}catch(SQLException e) {}
|
|
}
|
|
}
|