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

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=utf-8"%><%@page import="cn.js.fan.util.*"%><%@page import="cn.js.fan.web.*"%><%@page import="com.redmoon.oa.*"%><%@page import="com.redmoon.oa.dept.*"%><%@page import="com.redmoon.oa.netdisk.*"%><%@page import="java.util.*"%><%@page import="java.io.*"%><%@page import="java.net.*"%><jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/><jsp:useBean id="fsecurity" scope="page" class="cn.js.fan.security.SecurityUtil"/><jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/><%
  2. response.setHeader("Pragma","No-cache");
  3. response.setHeader("Cache-Control","no-cache");
  4. response.setDateHeader("Expires", 0);
  5. String priv = request.getParameter("priv");
  6. if (priv==null)
  7. priv = "read";
  8. if (!privilege.isUserPrivValid(request, priv))
  9. {
  10. //response.setContentType("text/html;charset=gb2312"); 
  11. out.print("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
  12. out.println(SkinUtil.makeErrMsg(request, SkinUtil.LoadString(request, "pvg_invalid")));
  13. return;
  14. }
  15. int id = ParamUtil.getInt(request, "id");
  16. int attId = ParamUtil.getInt(request, "attachId");
  17. Document mmd = new Document();
  18. mmd = mmd.getDocument(id);
  19. if (mmd==null || !mmd.isLoaded()) {
  20. out.print("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
  21. out.println("文件不存在!");
  22. return;
  23. }
  24. Attachment att = mmd.getAttachment(1, attId);
  25. String ext = att.getExt(); // diskName.substring( len-3, len );
  26. LeafPriv lp = new LeafPriv(att.getDirCode());
  27. if (!lp.canUserModify(privilege.getUser(request))) {
  28. response.setHeader("Content-disposition","filename=" + StrUtil.GBToUnicode(att.getName()));
  29. if (ext.equals("doc"))
  30. response.setContentType("application/msword");
  31. else if (ext.equals("xls"))
  32. response.setContentType("application/vnd.ms-excel");
  33. out.print(SkinUtil.makeErrMsg(request, SkinUtil.LoadString(request, "pvg_invalid")));
  34. return;
  35. }
  36. String diskName = att.getDiskName();
  37. int len = diskName.length();
  38. response.setHeader("Content-disposition","filename=" + StrUtil.GBToUnicode(att.getName()));
  39. if (ext.equals("doc"))
  40. response.setContentType("application/msword");
  41. else if (ext.equals("xls"))
  42. response.setContentType("application/vnd.ms-excel");
  43. else {
  44. out.println("文件格式" + ext + "非法");
  45. return;
  46. }
  47. BufferedInputStream bis = null;
  48. BufferedOutputStream bos = null;
  49. try {
  50. bis = new BufferedInputStream(new FileInputStream(Global.getRealPath() + "/" + att.getVisualPath() + "/" + att.getDiskName()));
  51. bos = new BufferedOutputStream(response.getOutputStream());
  52. byte[] buff = new byte[2048];
  53. int bytesRead;
  54. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  55. bos.write(buff,0,bytesRead);
  56. }
  57. } catch(final IOException e) {
  58. System.out.println ( "出现IOException." + e + "---" + att.getFullPath());
  59. } finally {
  60. if (bis != null)
  61. bis.close();
  62. if (bos != null)
  63. bos.close();
  64. }
  65. %>