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

Jsp/Servlet

开发平台:

Java

  1. <%@ page contentType="text/html;charset=gb2312"%>
  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.task.*"%>
  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 taskId = ParamUtil.getInt(request, "taskId");
  24. int attId = ParamUtil.getInt(request, "attachId");
  25. TaskDb td = new TaskDb();
  26. td = td.getTaskDb(taskId);
  27. Attachment att = td.getAttachment(attId);
  28. // response.setContentType(MIMEMap.get(StrUtil.getFileExt(att.getDiskName())));
  29. response.setContentType(MIMEMap.get(StrUtil.getFileExt(att.getDiskName())));
  30. response.setHeader("Content-disposition","filename="+StrUtil.GBToUnicode(att.getName()));
  31. BufferedInputStream bis = null;
  32. BufferedOutputStream bos = null;
  33. try {
  34. bis = new BufferedInputStream(new FileInputStream(att.getFullPath()));
  35. bos = new BufferedOutputStream(response.getOutputStream());
  36. byte[] buff = new byte[2048];
  37. int bytesRead;
  38. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  39. bos.write(buff,0,bytesRead);
  40. }
  41. } catch(final IOException e) {
  42. System.out.println( "鍑虹幇IOException." + e );
  43. } finally {
  44. if (bis != null)
  45. bis.close();
  46. if (bos != null)
  47. bos.close();
  48. }
  49. %>