Link to home
Start Free TrialLog in
Avatar of tommyboy2214
tommyboy2214

asked on

response.setContentType("application/unknow"); response.setHeader

Hi

I am looking for an explanation on how i can use the response.setContentType("application/unknow") and response.setHeader to send an
XXX.exe to a client computer. I have a filed called XXX.exe already created and sitting on my webserver in the directory /usr/iplantet/servers/docs/Cognos/XXX.exe. I want to create a servlet that is in /usr/iplanet/servers/servlet/Cognos/ and when it runs all it does it send this exe file to
client computer and give them the option to save file. I dont want to save as a default .txt file but i want to save the file so it is still a .exe file by default. I am looking for an explanation on how setContentType and response.setHeader work and also how i can use them to do the above problem.

thanx for time
Avatar of girionis
girionis
Flag of Greece image

 Try: setContentType("application/octet-stream")
 The setHeader should be: setHeader("Content-Disposition", "attachment;filename=\"" + <filename here> +"\"");
Avatar of tommyboy2214
tommyboy2214

ASKER

is this all i need to do is set the header?
Also do i include the filepath to the file since servlet is in different directory than the file?


thanx
is this all i need to do is set the header?
Also do i include the filepath to the file since servlet is in different directory than the file?


thanx
 Yes that's all you should need. And yes, you should include the filepath to the file.
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes,
thats what i was looking for,
So that means you have to write the file to the output stream,

one more thing if you got a minute, i wanted to output some sort of page so i was wondering if it is possible to write some html to client and then change the response after i output a small page to the screen?

thanx
>>  i was wondering if it is possible to write some html to client and then change the response after i output a small page to the screen?

Not so sure if I understand your question. but here are some facts:
1. all header information must be send to client before any content. content type are part of header.
2. jsp page have buffer to cache the information you send to client. When buffer is full, header will be send to client and content follows.
3. once server send information to client, that's called "response is committed". you cannot change header information as soon as response is committed to client.
4. you can change jsp buffer size using page directive:
<%@ page buffer="64kb" %>

if this doesn't answer your question, please be more specific. thanks for your points.