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

OA系统

开发平台:

Java

  1. /*
  2.  * Created on 2004-9-25
  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.em;
  8. import oa.sys.*;
  9. import java.io.*;
  10. import java.sql.*;
  11. import javax.servlet.*;
  12. import javax.servlet.http.*;
  13. /**
  14.  ****************************************************
  15.  *类名称: Save<br>
  16.  *类功能: 保存员工信息<br>
  17.  *创建: 白伟明 2004年9月27日<br>
  18.  ****************************************************
  19.  * To change the template for this generated type comment go to
  20.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  21.  */
  22. public class Save extends HttpServlet{
  23. private Statement stmt=null;
  24. private String name,birthday,learn,post,tel,addr,sex,sql;
  25. private RequestDispatcher dispatcher=null;
  26. private HttpSession session=null;
  27. private int deid,jobid,stateid,temp,id;
  28. private PrintWriter out=null;
  29. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  30. request.setCharacterEncoding("gb2312");
  31. response.setContentType("text/html; charset=gb2312");
  32. out=response.getWriter();
  33. session=request.getSession();
  34. //获取数据
  35. name=(String)request.getParameter("name");
  36. sex=(String)request.getParameter("sex");
  37. birthday=(String)request.getParameter("birthday");
  38. learn=(String)request.getParameter("learn");
  39. post=(String)request.getParameter("post");
  40. tel=(String)request.getParameter("tel");
  41. addr=(String)request.getParameter("addr");
  42. try{
  43. id=Integer.parseInt(request.getParameter("id"));
  44. }catch(Exception e){
  45. id=0;
  46. }
  47. try{
  48. deid=Integer.parseInt((String)request.getParameter("depid"));
  49. }catch(Exception e){
  50. }
  51. try{
  52. jobid=Integer.parseInt((String)request.getParameter("jobid"));
  53. }catch(Exception e){
  54. }
  55. try{
  56. stateid=Integer.parseInt((String)request.getParameter("emsid"));
  57. }catch(Exception e){
  58. }
  59. Db db=new Db();
  60. Str str=new Str();
  61. //字符转换
  62. name=str.inStr(name);
  63. sex=str.inStr(sex);
  64. birthday=str.inStr(birthday);
  65. learn=str.inStr(learn);
  66. post=str.inStr(post);
  67. tel=str.inStr(tel);
  68. addr=str.inStr(addr);
  69. if(id!=0){
  70. sql="UPDATE eminfo SET name='"+name+"',sex='"+sex+"',birthday='"+birthday+"',learn='"
  71. +learn+"',post='"+post+"',departmentid="+deid+",jobid="+jobid+",tel='"+tel+"',addr='"
  72. +addr+"',stateid="+stateid+" WHERE employeeid="+id;
  73. }else{
  74. sql="INSERT INTO eminfo(name,sex,birthday,learn,post,departmentid,jobid,tel,addr,stateid)"
  75. +"VALUES('"+name+"','"+sex+"','"+birthday+"','"+learn+"','"+post+"',"+deid+","+jobid+",'"
  76. +tel+"','"+addr+"',"+stateid+")";
  77. }
  78. try{
  79. stmt=db.getStmt();
  80. temp=stmt.executeUpdate(sql);
  81. if(temp>0){
  82. request.setAttribute("msg","操作成功");
  83. }else{
  84. request.setAttribute("msg","操作失败");
  85. }
  86. }catch(Exception e){
  87. request.setAttribute("msg","操作失败,请先添加部门、职位和员工状态等信息");
  88. e.printStackTrace();
  89. }finally{
  90. db.close();
  91. if(id!=0){
  92. dispatcher=request.getRequestDispatcher("add?id="+id);
  93. }else{
  94. dispatcher=request.getRequestDispatcher("add.jsp");
  95. }
  96. dispatcher.forward(request,response);
  97. }
  98. }
  99. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  100. doPost(request,response);
  101. }
  102. }