Re: Servlet Streaming file to client: Can't override file name
What happens in FireFox if you do this: response.setHeader(Content-Disposition, attachment; filename=\ + theFile.getName() + \); The relevant spec is here: http://www.ietf.org/rfc/rfc2183.txt And for the definition of 'value' it references: http://www.ietf.org/rfc/rfc2045.txt The filename parameter must be quoted if it contains spaces. Jon Mark Leone wrote: Thanks. That's exactly what I needed, and it did the trick. Firefox browser just grabs the first non-whitespace part of the name, but in IE the entire name shows up. Thanks again. -Mark Chris Hyzer wrote: Servlet Streaming file to client: Can't override file name 123049 by: Mark Leone Its an HTTP header you are looking for, try this: response.setHeader(Content-Disposition, attachment; filename= + theFile.getName()); Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Servlet Streaming file to client: Can't override file name
Servlet Streaming file to client: Can't override file name 123049 by: Mark Leone Its an HTTP header you are looking for, try this: response.setHeader(Content-Disposition, attachment; filename= + theFile.getName()); Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Servlet Streaming file to client: Can't override file name
Thanks. That's exactly what I needed, and it did the trick. Firefox browser just grabs the first non-whitespace part of the name, but in IE the entire name shows up. Thanks again. -Mark Chris Hyzer wrote: Servlet Streaming file to client: Can't override file name 123049 by: Mark Leone Its an HTTP header you are looking for, try this: response.setHeader(Content-Disposition, attachment; filename= + theFile.getName()); Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Servlet Streaming file to client: Can't override file name
I wrote a simple servlet that streams a file to the requesting client. Everything works fine except I can't figure out how to override the filename that Tomcat provides by default to the client for the incoming file. The filename presened to the client is the name of the web app. The HttpServletResponse object that Tomcat passes to the servlet provides access to an OutputStream object, and I see no way to set the filename with an object of that class. If Tomcat passed a FileOutputStream object (child of OutputStream), I could call a constructor that sets the file name or file descriptor, but casting the OutputStream to a FileOutputStream is not permitted. According to the API, the OutputStream object that Tomcat passess to the servlet is actually a ServletOutputStream object, which is an abstract child of OutputStream. Is there a concrete child of ServletOutputStream that I could cast it to, that would let me specify the filename? Is this something configurable in Tomcat? Any other way to set the filename? Here's my servlet code. package FileSnatcher; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import javax.activation.MimetypesFileTypeMap; /** * pTitle: /p * * pDescription: /p * * pCopyright: Copyright (c) 2005/p * * pCompany: /p * * @author not attributable * @version 1.0 */ public class FileSender extends HttpServlet{ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ String file = request.getParameter(file); MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap (C:\\Program Files\\Java\\jdk1.5.0_01\\lib\\mime.types); String mime = mimeTypes.getContentType(new File(file)); response.setContentType(mime); FileInputStream in = new FileInputStream(new File(file)); OutputStream out = response.getOutputStream(); byte[] buf = new byte[1024]; int i = 0; while((i=in.read(buf))!=-1) { out.write(buf, 0, i); } in.close(); out.close(); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]