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

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-18
  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.login;
  8. import oa.sys.*;
  9. import oa.data.*;
  10. import java.io.*;
  11. import java.sql.*;
  12. import java.util.*;
  13. import javax.servlet.*;
  14. import javax.servlet.http.*;
  15. /**
  16.  ****************************************************
  17.  *类名称: Em<br>
  18.  *类功能: 验证员工登录<br>
  19.  *创建: 白伟明 2004年9月28日<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 Em extends HttpServlet{
  25. private boolean flag=true;
  26. private String state;
  27. private String job;
  28. private String dep;
  29. private int stateid;
  30. private String addr;
  31. private int jobid;
  32. private String tel;
  33. private String post;
  34. private int deid;
  35. private String learn;
  36. private String birthday;
  37. private int sex;
  38. private String name;
  39. private int id=0;
  40. private String password,sqls,sqls1;
  41. private RequestDispatcher dispatcher;
  42. private Statement stmt=null;
  43. private ResultSet rs=null;
  44. private Eminfo eminfo=null;
  45. private UserList list=null;
  46. private PrintWriter out = null;
  47. private HttpSession session=null;
  48. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  49.      request.setCharacterEncoding("gb2312");
  50.      response.setContentType("text/html;charset=gb2312");
  51. out = response.getWriter();
  52. session=request.getSession();
  53. //获取数据
  54. id=Integer.parseInt((String)request.getParameter("id"));
  55. password=request.getParameter("password");
  56. sqls="SELECT * FROM password WHERE employeeid="+id+" AND password='"+password+"'";
  57. Db db=new Db();
  58. Str str=new Str();
  59. //验证
  60. try{
  61. stmt=db.getStmtread();
  62. rs=stmt.executeQuery(sqls);
  63. if(rs.next()){
  64. db.close();
  65. //验证成功则获取基本信息
  66. sqls1="SELECT * FROM eminfo WHERE employeeid="+id;
  67. stmt=db.getStmtread();
  68. rs=stmt.executeQuery(sqls1);
  69. //有基本信息则增加在线列表
  70. if(rs.next()){
  71. id=rs.getInt(1);
  72. name=rs.getString(2);
  73. sex=rs.getInt(3);
  74. birthday=rs.getString(4);
  75. learn=rs.getString(5);
  76. post=rs.getString(6);
  77. deid=rs.getInt(7);
  78. jobid=rs.getInt(8);
  79. tel=rs.getString(9);
  80. addr=rs.getString(10);
  81. stateid=rs.getInt(11);
  82. db.close();
  83. dep=db.IdtoDo("Name","department WHERE departmentid="+deid);
  84. job=db.IdtoDo("Name","job WHERE jobid="+jobid);
  85. state=db.IdtoDo("Name","emstate WHERE stateid="+stateid);
  86. //字符转换*/
  87. name=str.outStr(name);
  88. birthday=birthday.substring(0,10);
  89. dep=str.outStr(dep);
  90. job=str.outStr(job);
  91. state=str.outStr(state);
  92. learn=str.outStr(learn);
  93. post=str.outStr(post);
  94. tel=str.outStr(tel);
  95. addr=str.outStr(addr);
  96. Eminfo eminfo=new Eminfo();
  97. eminfo.setId(id);
  98. eminfo.setName(name);
  99. eminfo.setSex(sex);
  100. eminfo.setBirthday(birthday);
  101. eminfo.setLearn(learn);
  102. eminfo.setPost(post);
  103. eminfo.setDepartment(dep);
  104. eminfo.setJob(job);
  105. eminfo.setTel(tel);
  106. eminfo.setAddr(addr);
  107. eminfo.setState(state);
  108. //判断是否有人在线
  109. list=UserList.getInstance();
  110. Vector  vc=list.getList();
  111. flag=true;
  112. if(!vc.isEmpty()&&vc!=null){
  113. Enumeration em=vc.elements();
  114. while(em.hasMoreElements()){
  115. Eminfo emin=(Eminfo)em.nextElement();
  116. if(emin.getId()==eminfo.getId()){
  117. //在线
  118. flag=false;
  119. }
  120. }
  121. }else{
  122. flag=true;
  123. }
  124. if(flag){
  125. UserTrace usertrace=new UserTrace();
  126. usertrace.setId(eminfo.getId());
  127. list.addUser(eminfo);
  128. session.setAttribute("list",usertrace);
  129. session.setAttribute("id",new Integer(eminfo.getId()).toString());
  130. out.print("<script>parent.location.href='login_ok.htm';</script>");
  131. }else{
  132. request.setAttribute("error","该用户名正在使用");
  133. dispatcher=request.getRequestDispatcher("/login/em.jsp");
  134. dispatcher.forward(request,response);
  135. }
  136. }//增加在线列表
  137. }else{
  138. //验证失败
  139. request.setAttribute("error","用户名或密码错误");
  140. dispatcher=request.getRequestDispatcher("/login/em.jsp");
  141. dispatcher.forward(request,response);
  142. }
  143. }catch(Exception e){
  144. e.printStackTrace();
  145. }finally{
  146. db.close();
  147. }
  148. }
  149. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  150. doPost(request,response);
  151. }
  152. }
  153.  
  154.