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

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=utf-8"%>
  2. <%@page import="cn.js.fan.util.*"%>
  3. <%@page import="cn.js.fan.web.Global"%>
  4. <%@page import="com.redmoon.oa.*"%>
  5. <%@page import="cn.js.fan.module.cms.*"%>
  6. <%@page import="java.util.*"%>
  7. <%@page import="java.io.*"%>
  8. <%@page import="java.net.*"%>
  9. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  10. <jsp:useBean id="fsecurity" scope="page" class="cn.js.fan.security.SecurityUtil"/>
  11. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  12. <%
  13. String priv = request.getParameter("priv");
  14. if (priv==null)
  15. priv = "read";
  16. if (!privilege.isUserPrivValid(request, priv))
  17. {
  18. //response.setContentType("text/html;charset=gb2312"); 
  19. out.print("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
  20. out.println(fchar.makeErrMsg("权限非法"));
  21. return;
  22. }
  23. int docId = ParamUtil.getInt(request, "docId");
  24. int attId = ParamUtil.getInt(request, "attachId");
  25. Document doc = new Document();
  26. doc = doc.getDocument(docId);
  27. Attachment att = doc.getAttachment(1, attId);
  28. response.setContentType(MIMEMap.get(StrUtil.getFileExt(att.getDiskName())));
  29. response.setHeader("Content-disposition","filename="+StrUtil.GBToUnicode(att.getName())); // 需加GBToUnicode,否则会打不开文件
  30. // response.setHeader("Content-disposition","filename="+att.getDiskName());
  31. // 使客户端直接下载,上句会使IE在本窗口中打开文件,下句也一样,晕
  32. // response.setContentType("application/octet-stream");
  33. // response.setHeader("Content-disposition","attachment; filename="+att.getName());
  34. BufferedInputStream bis = null;
  35. BufferedOutputStream bos = null;
  36. try {
  37. bis = new BufferedInputStream(new FileInputStream(att.getFullPath()));
  38. bos = new BufferedOutputStream(response.getOutputStream());
  39. byte[] buff = new byte[2048];
  40. int bytesRead;
  41. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  42. bos.write(buff,0,bytesRead);
  43. }
  44. } catch(final IOException e) {
  45. System.out.println( "IOException." + e );
  46. } finally {
  47. if (bis != null)
  48. bis.close();
  49. if (bos != null)
  50. bos.close();
  51. }
  52. %>