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

Jsp/Servlet

开发平台:

Java

  1. <%@page import="java.util.*"%>
  2. <%@page import="java.io.*"%>
  3. <%@page import="java.net.*"%>
  4. <jsp:useBean id="fchar" scope="page" class="cn.js.fan.util.StrUtil"/>
  5. <jsp:useBean id="cfgparser" scope="page" class="fan.util.CFGParser"/>
  6. <jsp:useBean id="fsecurity" scope="page" class="fan.util.fsecurity"/>
  7. <jsp:useBean id="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  8. <%
  9. String priv = request.getParameter("priv");
  10. if (priv==null)
  11. priv = "read";
  12. String user = fchar.UnicodeToGB(request.getParameter("user"));
  13. String pwd = request.getParameter("pwd");
  14. if (user==null)
  15. {
  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(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
  21. return;
  22. }
  23. }
  24. else
  25. {
  26. if (!privilege.isUserPrivValid(user,fsecurity.MD5(pwd),priv))
  27. {
  28. out.println(cn.js.fan.web.SkinUtil.makeErrMsg(request, cn.js.fan.web.SkinUtil.LoadString(request, "pvg_invalid")));
  29. return;
  30. }
  31. }
  32. String id = request.getParameter("id");
  33. String filename = fchar.UnicodeToGB(request.getParameter("filename"));
  34. String extname = request.getParameter("extname");
  35. if (filename==null) {
  36. out.print(fchar.p_center("缺少文件名!"));
  37. return;
  38. }
  39. filename = filename + "." + extname;
  40. cfgparser.parse("config.xml");
  41. Properties props = cfgparser.getProps();
  42. String noticefilepath = props.getProperty("noticefilepath");
  43. response.setContentType("application/"+extname);
  44. response.setHeader("Content-disposition","attachment; filename="+filename);
  45. BufferedInputStream bis = null;
  46. BufferedOutputStream bos = null;
  47. try {
  48. bis = new BufferedInputStream(new FileInputStream(noticefilepath+filename));
  49. bos = new BufferedOutputStream(response.getOutputStream());
  50. byte[] buff = new byte[2048];
  51. int bytesRead;
  52. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  53. bos.write(buff,0,bytesRead);
  54. }
  55. } catch(final IOException e) {
  56. System.out.println ( "出现IOException." + e );
  57. } finally {
  58. if (bis != null)
  59. bis.close();
  60. if (bos != null)
  61. bos.close();
  62. }
  63. %>