Select.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.Statement;
  12. import java.util.ArrayList;
  13. import java.util.Collection;
  14. import javax.servlet.RequestDispatcher;
  15. import javax.servlet.ServletException;
  16. import javax.servlet.http.HttpServlet;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import oa.data.Department;
  20. import oa.sys.Db;
  21. import oa.sys.Str;
  22. /**
  23.  ****************************************************
  24.  *类名称: Select<br>
  25.  *类功能: 查找部门信息<br>
  26.  *创建: 白伟明 2004年9月23日<br>
  27.  ****************************************************
  28.  * To change the template for this generated type comment go to
  29.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  30.  */
  31. public class Select  extends HttpServlet{
  32. private Statement stmt=null;
  33. private ResultSet rs=null;
  34. private String name,explain,sqls,flag;
  35. private RequestDispatcher dispatcher;
  36. private int id=0;
  37. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  38. request.setCharacterEncoding("gb2312");
  39. response.setContentType("text/html; charset=gb2312");
  40. Db db=new Db();
  41. Str str=new Str();
  42. PrintWriter out=response.getWriter();
  43. try{
  44. id=Integer.parseInt((String)request.getParameter("id"));
  45. }catch(Exception e){
  46. }
  47. flag=request.getParameter("flag");
  48. sqls="SELECT * FROM department WHERE departmentid="+id;
  49. Collection ret=new ArrayList();
  50. try{
  51. stmt=db.getStmtread();
  52. rs=stmt.executeQuery(sqls);
  53. //判断是否有数据
  54. if(rs.next()){
  55. rs.beforeFirst();
  56. if(rs.next()){
  57. id=rs.getInt(1);
  58. name=rs.getString(2);
  59. explain=rs.getString(3);
  60. name=str.outStr(name);
  61. explain=str.outStr(explain);
  62. Department dep=new Department();
  63. dep.setId(id);
  64. dep.setName(name);
  65. dep.setExplain(explain);
  66. ret.add(dep);
  67. }
  68. request.setAttribute("msg2",ret);
  69. }
  70. db.close();
  71. }catch(Exception e){
  72. e.printStackTrace();
  73. }finally{
  74. if(flag!=null){
  75. dispatcher=request.getRequestDispatcher("del.jsp");
  76. }else{
  77. dispatcher=request.getRequestDispatcher("change.jsp");
  78. }
  79. dispatcher.forward(request,response);
  80. }
  81. }
  82. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  83. doPost(request,response);
  84. }
  85. }