www.pudn.com > OA.rar > Save.java
/* * Created on 2004-9-24 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.bumf; import oa.sys.*; import oa.sys.Time; import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import com.jspsmart.upload.*; import com.jspsmart.upload.File; /** **************************************************** *类名称: Send
*类功能: 公文发送(附件)
*创建: 白伟明 2004年10月7日
**************************************************** * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class Save extends HttpServlet{ private String affix;//保存附件名称 private String sqli;//保存SQL语句 private String submit;//保存表单中的按钮 private String filepath;//附件路径 private String filename;//附件名称 private String bumf;//公文内容 private HttpSession session=null; private JspFactory jspxFactory = null;//工厂类对象 private PageContext pagecontext=null; private ResultSet rs=null; private Statement stmt=null; private String title,sqls,sqlu;//保存公文标题和SQL语句 //分别用于保存stmt.executeUpdate()的运行结果、发送者编号、员工id、文件大小、是否已发送、公文id private int temp,id,emid,filesize,sign,bumfid; public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ request.setCharacterEncoding("gb2312"); response.setContentType("text/html; charset=gb2312"); PrintWriter out=response.getWriter(); session=request.getSession(); Str str=new Str(); Db db=new Db(); Time time=new Time(); SmartUpload supload=new SmartUpload(); jspxFactory=javax.servlet.jsp.JspFactory.getDefaultFactory(); pagecontext=jspxFactory.getPageContext(this, request, response,"", true, 8192, true); supload.initialize(pagecontext); try { supload.upload(); } catch (Exception e) { e.printStackTrace(); } //获取发送人id try{ id=Integer.parseInt((String)session.getAttribute("id")); }catch(Exception e){ e.printStackTrace(); request.setAttribute("ok","您的网页已过期请重新登录"); } //获取基本信息 try{ emid=Integer.parseInt((String)supload.getRequest().getParameter("emid")); }catch(Exception e){ e.printStackTrace(); } title=supload.getRequest().getParameter("title"); bumf=supload.getRequest().getParameter("bumf"); try{ bumfid=Integer.parseInt((String)supload.getRequest().getParameter("bumfid")); }catch(Exception e){ e.printStackTrace(); } submit=supload.getRequest().getParameter("Submit"); title=str.inStr(title); bumf=str.inStr(bumf); if(submit.equals("现在发送")){ sign=1; }else{ sign=0; } //上传文件 File file=supload.getFiles().getFile(0); filename=file.getFileName(); filesize=file.getSize(); filepath=file.getFilePathName(); if (!file.isMissing()){ try { file.saveAs("/upload/"+id+filename); } catch (Exception e1) { e1.printStackTrace(); } }else{ filename=null; filesize=0; filepath=""; } if(filename!=null){ affix=id+filename; }else{ affix=""; } if(sign==0){ //如果用户点击保存按钮,执行以下操作 sqlu="UPDATE bumf SET sendter="+id+",accepter="+id+",title='"+title+ "',time='"+time.getYMDHMS()+"',content='"+bumf+"',affix='"+affix+ "',examine="+1+",sign="+sign+" WHERE bumfid="+bumfid; try{ stmt=db.getStmt(); temp=stmt.executeUpdate(sqlu); if(temp>0){ request.setAttribute("ok","操作成功"); }else{ request.setAttribute("ok","操作失败"); } db.close(); }catch(Exception e){ e.printStackTrace(); } }else{ //当用户点击发送按钮时,执行以下操作 sqls="SELECT * FROM eminfo WHERE employeeid="+emid; sqlu="UPDATE bumf SET sendter="+id+",accepter="+emid+",title='"+title+ "',time='"+time.getYMDHMS()+"',content='"+bumf+"',affix='"+affix+ "',examine="+0+",sign="+sign+" WHERE bumfid="+bumfid; try { stmt=db.getStmtread(); rs=stmt.executeQuery(sqls);//执行SQL语句并获得ResultSet对象 if(rs.next()){ db.close(); stmt=db.getStmt(); temp=stmt.executeUpdate(sqlu); if(temp>0){ request.setAttribute("ok","操作成功"); }else{ request.setAttribute("ok","操作失败"); } db.close(); }else{ request.setAttribute("ok","接收人ID并不存在"); db.close(); } } catch (SQLException e) { e.printStackTrace(); } } RequestDispatcher dispatcher=request.getRequestDispatcher("send"); dispatcher.forward(request,response); } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ doPost(request,response); } }