getdoc.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="privilege" scope="page" class="com.redmoon.oa.pvg.Privilege"/>
  7. <%
  8. String priv = request.getParameter("priv");
  9. if (priv==null)
  10. priv = "read";
  11. String user = fchar.UnicodeToGB(request.getParameter("user"));
  12. String pwd = request.getParameter("pwd");
  13. if (user==null)
  14. {
  15. if (!privilege.isUserPrivValid(request,priv))
  16. {
  17. out.println(fchar.makeErrMsg("     ʴ   "));
  18. return;
  19. }
  20. }
  21. else
  22. {
  23. if (!privilege.isUserPrivValid(user,pwd,priv))
  24. {
  25. out.println(fchar.makeErrMsg("     ʴ   "));
  26. return;
  27. }
  28. }
  29. String filename = fchar.UnicodeToGB(request.getParameter("filename"));
  30. if (filename==null) {
  31. out.print(fchar.p_center("ȱ   "));
  32. return;
  33. }
  34. cfgparser.parse("config.xml");
  35. Properties props = cfgparser.getProps();
  36. String documentpath = props.getProperty("documentpath");
  37. response.setHeader("Content-disposition","attachment; filename="+filename);
  38. response.setContentType("application/msword");
  39. //response.setContentLength(bytes.length);
  40. BufferedInputStream bis = null;
  41. BufferedOutputStream bos = null;
  42. try {
  43. bis = new BufferedInputStream(new FileInputStream(documentpath+ filename));
  44. bos = new BufferedOutputStream(response.getOutputStream());
  45. byte[] buff = new byte[2048];
  46. int bytesRead;
  47. while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
  48. bos.write(buff,0,bytesRead);
  49. }
  50. } catch(final IOException e) {
  51. System.out.println ( "  IOException." + e );
  52. } finally {
  53. if (bis != null)
  54. bis.close();
  55. if (bos != null)
  56. bos.close();
  57. }
  58. %>