37c27ae4608eb1e57b26e5985e3c618e7aaaf296.svn-base 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ page language="java" import="java.io.*,java.io.OutputStream,java.net.URLEncoder,javax.servlet.*" %>
  4. <%
  5. String FileName = request.getParameter("dakai");
  6. FileName = java.net.URLDecoder.decode(FileName, "UTF-8");//解决javaScript传参乱码
  7. System.out.println("文件名:"+FileName);
  8. //String name=this.getServletContext().getRealPath("")+"/HHH/Sunset.jpg";
  9. String name = "/home/appuser/nwyj/upload/"+FileName;
  10. //response.setHeader("Content-Disposition", "attachment; filename="+URLEncoder.encode(FileName,"GBK"));
  11. InputStream in = new FileInputStream(name);
  12. OutputStream Out = response.getOutputStream();
  13. try
  14. {
  15. int len = 0;
  16. byte[] buffer = new byte[1024];
  17. while((len = in.read(buffer,0,1024)) != -1)
  18. {
  19. Out.write(buffer,0,len);
  20. }
  21. out.clear();
  22. out = pageContext.pushBody();
  23. }
  24. finally
  25. {
  26. if(in != null)
  27. {
  28. try
  29. {
  30. in.close();
  31. }
  32. catch(Exception e)
  33. {
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38. %>
  39. </head>
  40. <body>
  41. </body>
  42. </html>