Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-12
8
Medium Priority
?
1,459 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:tommyboy2214
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8120202
 Try: setContentType("application/octet-stream")
0
 
LVL 35

Expert Comment

by:girionis
ID: 8120217
 The setHeader should be: setHeader("Content-Disposition", "attachment;filename=\"" + <filename here> +"\"");
0
 

Author Comment

by:tommyboy2214
ID: 8120241
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:tommyboy2214
ID: 8120263
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
 
LVL 35

Expert Comment

by:girionis
ID: 8120288
 Yes that's all you should need. And yes, you should include the filepath to the file.
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 1000 total points
ID: 8121531
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
 

Author Comment

by:tommyboy2214
ID: 8122273
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8123372
>>  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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This applies to Dell but may also apply to other manufacturers as well. We ran across a few machines that just dropped recently it trust relationship with the server. After doing the basic removing and joining the domain again, it changed to No logo…
Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question