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

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html; charset=utf-8" %>
  2. <%@page import="java.util.*"%>
  3. <%@page import="java.io.*"%>
  4. <%@page import="java.net.*"%>
  5. <%@ page import="cn.js.fan.util.*"%>
  6. <%@ page import="cn.js.fan.web.*"%>
  7. <%@ page import="com.redmoon.oa.flow.*"%>
  8. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  9. <%
  10. response.setHeader("Pragma","No-cache");
  11. response.setHeader("Cache-Control","no-cache");
  12. response.setDateHeader("Expires", 0);
  13. String priv="read";
  14. if (!privilege.isUserPrivValid(request,priv))
  15. {
  16. out.println(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
  17. return;
  18. }
  19. //String department_id = privilege.getDepartmentID(request);
  20. //String document_id = request.getParameter("document_id");
  21. //String priv = "department";//部门管理
  22. //String user = fchar.UnicodeToGB(request.getParameter("user"));
  23. //String pwd = request.getParameter("pwd");
  24. //if (!document.canModifyDoc(document_id,department_id) && !privilege.isUserPrivValid(user,pwd,priv))
  25. //{
  26. // out.println(fchar.makeErrMsg("警告非法用户,你无访问此页的权限!"));
  27. // return;
  28. //}
  29. int docId = ParamUtil.getInt(request, "doc_id");
  30. int fileId = ParamUtil.getInt(request, "file_id");
  31. DocumentMgr dm = new DocumentMgr();
  32. Document doc = dm.getDocument(docId);
  33. Attachment att = doc.getAttachment(1, fileId);
  34. if (att==null) {
  35. out.println("取文件" + docId + "的附件" + fileId + "时,未找到!");
  36. return;
  37. }
  38. // System.out.print("att name=" + att.getName() + " diskName=" + att.getDiskName());
  39. String diskName = att.getDiskName();
  40. int len = diskName.length();
  41. // 当att.getName()为中文时,会导致控件在解析attachment; filename=时,读取不到后面的中文,待查
  42. // response.setHeader("Content-disposition","attachment; filename="+att.getName());
  43. response.setHeader("Content-disposition","attachment; filename="+att.getDiskName());
  44. String ext = diskName.substring( len-3, len );
  45. if (ext.equals("doc"))
  46. response.setContentType("application/msword");
  47. else if (ext.equals("xls"))
  48. response.setContentType("application/vnd.ms-excel");
  49. else {
  50. out.println("文件格式" + ext + "非法");
  51. return;
  52. }
  53. BufferedInputStream bis = null;
  54. BufferedOutputStream bos = null;
  55. try {
  56. bis = new BufferedInputStream(new FileInputStream(att.getFullPath()));
  57. bos = new BufferedOutputStream(response.getOutputStream());
  58. byte[] buff = new byte[2048];
  59. int bytesRead;
  60. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  61. bos.write(buff,0,bytesRead);
  62. }
  63. } catch(final IOException e) {
  64. System.out.println ( "出现IOException." + e + "---" + att.getFullPath());
  65. } finally {
  66. if (bis != null)
  67. bis.close();
  68. if (bos != null)
  69. bos.close();
  70. }
  71. %>