?
Solved

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

Posted on 2003-03-12
8
Medium Priority
?
1,438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The Summer 2017 Scholarship Winners have been announced!
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

764 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