Del.java
上传用户:sxwtmm
上传日期:2022-08-11
资源大小:2183k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-24
  3.  *
  4.  * To change the template for this generated file go to
  5.  * Window>Preferences>Java>Code Generation>Code and Comments
  6.  */
  7. package com.department;
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import javax.servlet.RequestDispatcher;
  14. import javax.servlet.ServletException;
  15. import javax.servlet.http.HttpServlet;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpServletResponse;
  18. import javax.servlet.http.HttpSession;
  19. import oa.sys.Db;
  20. import oa.sys.Str;
  21. /**
  22.  ****************************************************
  23.  *类名称: Del<br>
  24.  *类功能: 删除部门信息<br>
  25.  *创建: 白伟明 2004年9月25日<br>
  26.  ****************************************************
  27.  * To change the template for this generated type comment go to
  28.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  29.  */
  30. public class Del extends HttpServlet{
  31. private HttpSession session=null;
  32. private Statement stmt=null;
  33. private ResultSet rs=null;
  34. private String sqld,sqls;
  35. private int temp=0,id=0;
  36. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  37. request.setCharacterEncoding("gb2312");
  38. response.setContentType("text/html; charset=gb2312");
  39. Str str=new Str();
  40. Db db=new Db();
  41. PrintWriter out=response.getWriter();
  42. session=request.getSession();
  43. try{
  44. id=Integer.parseInt((String)request.getParameter("id"));
  45. }catch(NumberFormatException e){
  46. e.printStackTrace();
  47. }
  48. sqld="DELETE FROM department WHERE departmentid="+id;
  49. sqls="SELECT * FROM department WHERE departmentid="+id;
  50. stmt=db.getStmtread();
  51. try {
  52. rs=stmt.executeQuery(sqls);
  53. //查询添加部门是否存在
  54. if(rs.next()){
  55. rs.close();
  56. stmt.close();
  57. //删除部门
  58. stmt=db.getStmt();
  59. temp=stmt.executeUpdate(sqld);
  60. if(temp>0){
  61. request.setAttribute("delmsg","删除成功");
  62. }else{
  63. request.setAttribute("delmsg","删除失败");
  64. }
  65. }else{
  66. request.setAttribute("delmsg","该部门不存在");
  67. }
  68. } catch (SQLException e) {
  69. request.setAttribute("delmsg","删除失败,请删除属于此部门的所有员工");
  70. System.err.print(e.getMessage());
  71. }finally{
  72. db.close();
  73. RequestDispatcher dispatcher=request.getRequestDispatcher("del.jsp");
  74. dispatcher.forward(request,response);
  75. }
  76. }
  77. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  78. doPost(request,response);
  79. }
  80. }