A question about a program given in Head First Servlets and JSP book
Parthiban Malayandi
Ranch Hand
Joined: Apr 15, 2008
Posts: 67
posted
0
Hi all,
I'm learning servlets and JSP from "Head First Servlets and JSP" .In chapter 4 I came across an example which illustrate use of output stream by simply downloading a (jar) file .
I tried and understood the concept but what surprised me is that while downloading It didn't recognize the format(file extension .jar) instead of that it displays the name which is given in url-pattern is displaying (****.do)
This what that program does :
Simply getting the input stream of that jar file and writing it to the response's output stream
I think that's why it behaves like that .
What I understood is correct ?
I want it should recognize the file name and format when downloaded .
How can I do that ?
Thanks in advance
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
The servlet should set the Content-Disposition header; something like this should do the trick:
Whenever you do a response.setHeader, you are sending some instruction to the browser (which initiated the request). In this case with "Content-Disposition" you are advising the browser how to handle the content being streamed to it.
Ulf Dittmer's code says that the browser should treat the response body as an attachment and that it's name to be shown in the File Download dialog is "myFooBar.jar"
Hope this helps!
karthick Soundararaj
Greenhorn
Joined: Mar 09, 2009
Posts: 26
posted
0
hareendran dileep wrote:Karthick,
Whenever you do a response.setHeader, you are sending some instruction to the browser (which initiated the request). In this case with "Content-Disposition" you are advising the browser how to handle the content being streamed to it.
Ulf Dittmer's code says that the browser should treat the response body as an attachment and that it's name to be shown in the File Download dialog is "myFooBar.jar"
Hope this helps!
Thank you.. Now , how do you find these kind of values and header names.. Yes, googling can give us 100's of pages. But still, how does someone himself find the header needed for a particular action?