getdoctomodify.jsp
上传用户:jhtang88
上传日期:2014-01-27
资源大小:28528k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@page import="java.util.*"%>
  2. <%@page import="java.io.*"%>
  3. <%@page import="java.net.*"%>
  4. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  5. <jsp:useBean id="cfgparser" scope="page" class="fan.util.CFGParser"/>
  6. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  7. <jsp:useBean id="document" scope="page" class="com.redmoon.oa.document.Document"/>
  8. <%
  9. String department_id = privilege.getDepartmentID(request);
  10. String document_id = request.getParameter("document_id");
  11. String priv = "department";//  
  12. String user = fchar.UnicodeToGB(request.getParameter("user"));
  13. String pwd = request.getParameter("pwd");
  14. if (!document.canModifyDoc(document_id,department_id) && !privilege.isUserPrivValid(user,pwd,priv))
  15. {
  16. return;
  17. }
  18. String filename = fchar.UnicodeToGB(request.getParameter("filename"));
  19. //System.out.println("filename="+filename);
  20. if (filename==null) {
  21. out.print(fchar.p_center("ȱ   "));
  22. return;
  23. }
  24. cfgparser.parse("config.xml");
  25. Properties props = cfgparser.getProps();
  26. String documentpath = props.getProperty("documentpath");
  27. response.setContentType("application/msword");
  28. response.setHeader("Content-disposition","attachment; filename="+filename);
  29. BufferedInputStream bis = null;
  30. BufferedOutputStream bos = null;
  31. try {
  32. bis = new BufferedInputStream(new FileInputStream(documentpath+ filename));
  33. bos = new BufferedOutputStream(response.getOutputStream());
  34. byte[] buff = new byte[2048];
  35. int bytesRead;
  36. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  37. bos.write(buff,0,bytesRead);
  38. }
  39. } catch(final IOException e) {
  40. System.out.println ( "  IOException." + e + "---" + documentpath + filename);
  41. } finally {
  42. if (bis != null)
  43. bis.close();
  44. if (bos != null)
  45. bos.close();
  46. }
  47. %>