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

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.bumf;
  8. import oa.sys.*;
  9. import oa.sys.Time;
  10. import java.io.*;
  11. import java.sql.*;
  12. import javax.servlet.*;
  13. import javax.servlet.http.*;
  14. import javax.servlet.jsp.*;
  15. import com.jspsmart.upload.*;
  16. import com.jspsmart.upload.File;
  17. /**
  18.  ****************************************************
  19.  *类名称: Send<br>
  20.  *类功能: 公文发送(附件)<br>
  21.  *创建: 白伟明 2004年10月7日<br>
  22.  ****************************************************
  23.  * To change the template for this generated type comment go to
  24.  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
  25.  */
  26. public class Save extends HttpServlet{
  27. private String affix;
  28. private String sqli;
  29. private String submit;
  30. private String filepath;
  31. private String filename;
  32. private String bumf;
  33. private HttpSession session=null;
  34. private JspFactory jspxFactory = null;
  35. private PageContext pagecontext=null;
  36. private ResultSet rs=null;
  37. private Statement stmt=null;
  38. private String title,sqls,sqlu;
  39. private int temp,id,emid,filesize,sign,bumfid;
  40. public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  41. request.setCharacterEncoding("gb2312");
  42. response.setContentType("text/html; charset=gb2312");
  43. PrintWriter out=response.getWriter();
  44. session=request.getSession();
  45. Str str=new Str();
  46. Db db=new Db();
  47. Time time=new Time();
  48. SmartUpload supload=new SmartUpload();
  49. jspxFactory=JspFactory.getDefaultFactory();
  50. pagecontext=jspxFactory.getPageContext(this, request, response,"", true, 8192, true);
  51. supload.initialize(pagecontext);
  52. try {
  53. supload.upload();
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. //获取发送人id
  58. try{
  59. id=Integer.parseInt((String)session.getAttribute("id"));
  60. }catch(Exception e){
  61. e.printStackTrace();
  62. request.setAttribute("ok","您的网页已过期请重新登录");
  63. }
  64. //获取基本信息
  65. try{
  66. emid=Integer.parseInt((String)supload.getRequest().getParameter("emid"));
  67. }catch(Exception e){
  68. e.printStackTrace();
  69. }
  70. title=supload.getRequest().getParameter("title");
  71. bumf=supload.getRequest().getParameter("bumf");
  72. try{
  73. bumfid=Integer.parseInt((String)supload.getRequest().getParameter("bumfid"));
  74. }catch(Exception e){
  75. e.printStackTrace();
  76. }
  77. submit=supload.getRequest().getParameter("Submit");
  78. title=str.inStr(title);
  79. bumf=str.inStr(bumf);
  80. if(submit.equals("现在发送")){
  81. sign=1;
  82. }else{
  83. sign=0;
  84. }
  85. //上传文件
  86. File file=supload.getFiles().getFile(0);
  87. filename=file.getFileName();
  88. filesize=file.getSize();
  89. filepath=file.getFilePathName();
  90. if (!file.isMissing()){
  91. try {
  92. file.saveAs("/upload/"+id+filename);
  93. } catch (Exception e1) {
  94. e1.printStackTrace();
  95. }
  96. }else{
  97. filename=null;
  98. filesize=0;
  99. filepath="";
  100. }
  101. if(filename!=null){
  102. affix=id+filename;
  103. }else{
  104. affix="";
  105. }
  106. if(sign==0){
  107. //保存
  108. sqlu="UPDATE bumf SET sendter="+id+",accepter="+id+",title='"+title+"',time='"+time.getYMDHMS()
  109. +"',content='"+bumf+"',affix='"+affix+"',examine="+1+",sign="+sign+" WHERE bumfid="+bumfid;
  110. try{
  111. stmt=db.getStmt();
  112. temp=stmt.executeUpdate(sqlu);
  113. if(temp>0){
  114. request.setAttribute("ok","操作成功");
  115. }else{
  116. request.setAttribute("ok","操作失败");
  117. }
  118. db.close();
  119. }catch(Exception e){
  120. e.printStackTrace();
  121. }
  122. }else{
  123. //发送
  124. sqls="SELECT * FROM eminfo WHERE employeeid="+emid;
  125. sqlu="UPDATE  bumf SET sendter="+id+",accepter="+emid+",title='"+title+"',time='"+time.getYMDHMS()
  126. +"',content='"+bumf+"',affix='"+affix+"',examine="+0+",sign="+sign+" WHERE bumfid="+bumfid;
  127. try {
  128. stmt=db.getStmtread();
  129. rs=stmt.executeQuery(sqls);
  130. if(rs.next()){
  131. db.close();
  132. stmt=db.getStmt();
  133. if(temp>0){
  134. request.setAttribute("ok","操作成功");
  135. }else{
  136. request.setAttribute("ok","操作失败");
  137. }
  138. db.close();
  139. }else{
  140. request.setAttribute("ok","接收人ID并不存在");
  141. db.close();
  142. }
  143. } catch (SQLException e) {
  144. e.printStackTrace();
  145. }
  146. }
  147. RequestDispatcher dispatcher=request.getRequestDispatcher("send");
  148. dispatcher.forward(request,response);
  149. }
  150. public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  151. doPost(request,response);
  152. }
  153. }