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
tommyboy2214Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
 Try: setContentType("application/octet-stream")
0
girionisCommented:
 The setHeader should be: setHeader("Content-Disposition", "attachment;filename=\"" + <filename here> +"\"");
0
tommyboy2214Author Commented:
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
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

tommyboy2214Author Commented:
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
0
girionisCommented:
 Yes that's all you should need. And yes, you should include the filepath to the file.
0
kennethxuCommented:
a lot of book/post suggested to use application/octet-stream, but my real world experience is application/unknow works best. octet-stream won't work with some version of IE on some windows platform, the behavior is not consistant. you can try it out.

for the "Content-Disposition" header, I have gave you an example in your other question. notice that the filename part must be just the filename, you should not include any path info, otherwise, it won't work.

in addition to this, your servlet must transfer the file content to servlet output stream. it should like this:


                        File file = new File("/usr/iplantet/servers/docs/Cognos/XXX.exe");
                        out = new BufferedOutputStream( response.getOutputStream() );
                   response.setContentType( "application/unknow" );
                        response.setHeader("Content-Disposition","attachment; filename=\"" + file.getName() + "\"");

                        in = new BufferedInputStream( new FileInputStream( file ) );
                        int c;
                        while( ( c = in.read() ) != -1 ) out.write( c );
                        in.close(); in = null;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tommyboy2214Author Commented:
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
0
kennethxuCommented:
>>  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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.