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="java.util.*"%>
  6. <%@page import="java.io.*"%>
  7. <%@page import="java.net.*"%>
  8. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  9. <jsp:useBean id="fsecurity" scope="page" class="cn.js.fan.security.SecurityUtil"/>
  10. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  11. <%
  12. String priv = request.getParameter("priv");
  13. if (priv==null)
  14. priv = "read";
  15. String user = ParamUtil.get(request, "user");
  16. String pwd = request.getParameter("pwd");
  17. if (user==null)
  18. {
  19. if (!privilege.isUserPrivValid(request, priv))
  20. {
  21. //response.setContentType("text/html;charset=gb2312"); 
  22. out.print("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
  23. out.println(fchar.makeErrMsg("警告非法用户,你无访问此页的权限!"));
  24. return;
  25. }
  26. }
  27. else
  28. {
  29. // if (!privilege.isUserPrivValid(user,fsecurity.MD5(pwd),priv))
  30. // {
  31. // out.println(fchar.makeErrMsg("警告非法用户,你无访问此页的权限!"));
  32. // return;
  33. //}
  34. }
  35. String filename = ParamUtil.get(request, "filename");
  36. String extname = request.getParameter("extname");
  37. String prop = request.getParameter("prop");
  38. if (filename==null) {
  39. out.print(fchar.p_center("缺少文件名!"));
  40. return;
  41. }
  42. filename = filename + "." + extname;
  43. Config cfg = new Config();
  44. String noticefilepath = cfg.get(prop);
  45. response.setContentType("application/"+extname);
  46. response.setHeader("Content-disposition","attachment; filename="+filename);
  47. BufferedInputStream bis = null;
  48. BufferedOutputStream bos = null;
  49. try {
  50. bis = new BufferedInputStream(new FileInputStream(Global.getRealPath() + "/" + noticefilepath+"/" +filename));
  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 );
  59. } finally {
  60. if (bis != null)
  61. bis.close();
  62. if (bos != null)
  63. bos.close();
  64. }
  65. %>