Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

[jboss-user] [Tomcat, HTTPD,
 Servlets & JSP] - 3 Extra cr-lf downloading files

scott.stark@jboss.org

2007-06-14


Hey all, my problem is i am downloading some files via http using Jboss 4.0 and i get 3 extra cr-lf at the end of the files i download (zip, pdf, txt... all the files have 6 extra bytes at the end).
My code is in a jsp:

<%@(protected),
          java.io.InputStream,
          java.io.FileInputStream,
          java.io.OutputStream"%>
<%@(protected)" %>
<%
  String contentType = (String)application.getAttribute("fileupload_type");
  String fileName = (String)application.getAttribute("fileupload_name");
 
  String allowCache = "true";
  String openDirectly = "false";
 
  if(allowCache == null || allowCache.equalsIgnoreCase("false"))
  {
    response.setHeader("pragma", "no-cache");
    response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
    response.setHeader("Expires", "01 Apr 1995 01:10:10 GMT");
  }

  if(contentType!=null)
  {
    response.setContentType(contentType);
  }

  if(fileName != null)
  {
    fileName = fileName.substring(fileName.lastIndexOf('\\')+1);
    fileName = fileName.substring(fileName.lastIndexOf('/')+1);

    StringBuffer contentDisposition = new StringBuffer();

    if(openDirectly==null || openDirectly.equalsIgnoreCase("false"))
    {
       contentDisposition.append("attachment;");
    }

    contentDisposition.append("filename=\"");
    contentDisposition.append(fileName);
    contentDisposition.append("\"");

    response.setHeader ("Content-Disposition", contentDisposition.toString());
  }

  byte[] bytes = (byte[])application.getAttribute("fileupload_bytes");
  if (bytes != null)
  {
 response.setContentLength(bytes.length);
   response.getOutputStream().write(bytes);
   response.getOutputStream().flush();
   response.getOutputStream().close();
   response.flushBuffer();
%>

Thanks for your help.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4054473#4054473

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4054473
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.