• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Download from jsp  RSS feed

 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have a simple JSP that does nothing other than send output via the HttpServletResponse when someone clicks a link. My problem is that when you click this link - the IE File Download dialog appears ('would you like to open the file or save it to your computer?'....) which is all good, but the File name and File type listed in this dialog box are not what I want - so the correct application is not started. Here's the jsp:

And this works good - the dialog comes up on the remote computer and when I save it to disk and look at it, it's the correct text... but it is not opening with the correct application because the 'download dialog box' thinks this is a file of some abstract nonsense type. Is there a certain 'header' I can set to name this thing correctly? Figured this would have been addressed when setting the content type and making sure that is registered in web.xml
thanks in advance,
Terrance
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How a browser responds to the Contect Type returned has nothing to do with Server setup. The browser needs to have that content type mapped properly to the target application.

In Foxfire, this is configured under Tools - Options select the Downloads tab configure the exe that should be associated with the type.
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am using Tomcat 5.0, IE latest version running on win2K. I have set an association in windows explorer (tools->folder options->file types) for .vnc files to be opened appropriately with the vncviewer client app. This is how IE determines what applications get run when encountering certain types of files.

But if what is coming across my servletResponse cannot be identified as a ".vnc file" (but does have a content-type of 'application/x-myCompany-vnc'), shouldn't this also open the vncviewer app?

I guess I'm kinda confused on the purpose of even registering the mime type in web.xml if IE still doesn't know how to handle a file even though it is the correct content type, but incorrect extension.

does that make sense? I think I'm confusing myself....
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by terrance grahn:

I guess I'm kinda confused on the purpose of even registering the mime type in web.xml if IE still doesn't know how to handle a file even though it is the correct content type, but incorrect extension.


The mime types are how Tomcat knows which content-type to set for static files. MSIE has been known to ignore the mime types in the headers.
 
terrance grahn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved this - I needed to set an additional header in the response. In addition to the content type, I needed to set the content disposition... strange, never heard of that before. Here's what I needed to do:

for IE5.5
response.setHeader("Content-Disposition","file; filename=temp.vnc");

otherwise
response.setHeader("Content-Disposition","attachment; filename=temp.vnc");
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!