parent
43d042a468
commit
86cd700afe
@ -0,0 +1,112 @@
|
|||||||
|
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.AuthorityDao;
|
||||||
|
import com.dao.AuthorityDaoImpl;
|
||||||
|
import com.domain.Authority;
|
||||||
|
import com.domain.Tuser;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Servlet implementation class PostCheckServlet
|
||||||
|
*/
|
||||||
|
@WebServlet(name ="AuthorityServlet",urlPatterns={"/Authority.do"})
|
||||||
|
public class AuthorityServlet 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")){
|
||||||
|
removeAuthority(request,response);
|
||||||
|
}
|
||||||
|
else if (action.equals("list")){
|
||||||
|
listAuthority(request,response);
|
||||||
|
}else {
|
||||||
|
System.out.println("失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listAuthority(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
AuthorityDao dao = new AuthorityDaoImpl();
|
||||||
|
try{
|
||||||
|
|
||||||
|
List<Authority> list= dao.listAuthority();
|
||||||
|
request.setAttribute("AuthorityList",list);
|
||||||
|
|
||||||
|
}catch(SQLException e) {}
|
||||||
|
RequestDispatcher rd = request.getRequestDispatcher("da-authority.jsp");
|
||||||
|
|
||||||
|
rd.forward(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void removeAuthority(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
int Cid=Integer.parseInt(request.getParameter("Cid"));
|
||||||
|
AuthorityDao dao=new AuthorityDaoImpl();
|
||||||
|
try {
|
||||||
|
int success=dao.removeAuthority(Cid);
|
||||||
|
if(success>0) {
|
||||||
|
listAuthority(request,response);
|
||||||
|
}
|
||||||
|
}catch(SQLException e) {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue