email_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="com.redmoon.oa.emailpop3.*"%>
  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 id = ParamUtil.getInt(request, "id");
  24. int attId = ParamUtil.getInt(request, "attachId");
  25. MailMsgDb mmd = new MailMsgDb();
  26. mmd = mmd.getMailMsgDb(id);
  27. Attachment att = mmd.getAttachment(attId);
  28. // 用下句会使IE在本窗口中打开文件
  29. // response.setContentType(MIMEMap.get(StrUtil.getFileExt(att.getDiskName())));
  30. // 使客户端直接下载,上句会使IE在本窗口中打开文件,下句也一样,晕
  31. response.setContentType("application/octet-stream");
  32. response.setHeader("Content-disposition","attachment; filename="+att.getName());
  33. BufferedInputStream bis = null;
  34. BufferedOutputStream bos = null;
  35. try {
  36. bis = new BufferedInputStream(new FileInputStream(att.getFullPath()));
  37. bos = new BufferedOutputStream(response.getOutputStream());
  38. byte[] buff = new byte[2048];
  39. int bytesRead;
  40. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  41. bos.write(buff,0,bytesRead);
  42. }
  43. } catch(final IOException e) {
  44. System.out.println( "IOException: " + e );
  45. } finally {
  46. if (bis != null)
  47. bis.close();
  48. if (bos != null)
  49. bos.close();
  50. }
  51. %>