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