• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

TEXT Data Download in Browser.

I have JSP page which is Supposed to open pop up file for that client will download. But the Probelm is that when i try to out put this file to Client browser, render it itslef and didnt give any chance to download this file.
ANy idea that client will get popup to save this file on his hard disk?
0
ammad
Asked:
ammad
  • 4
  • 4
1 Solution
 
Richard QuadlingSenior Software DeveloperCommented:
Hi ammad,


The reason for that is that the browser has NOT been given any information that the data being received is NOT plain text or HTML.

You would need to issue a content-type header to tell the browser that the data is NOT understandable and ask the user to download it.

In PHP this would be ...

<?php
header('Content-type: application/octet-stream');
...
?>

You need to do something similar.

But that is only have the answer.

IE will sometimes use the extension of the filename and use that as a type. WHich is a pain.

Try issueing the header() (Not sure what the Java mechanism is).

You will normally also need to issue the header() before ANY other output.

Regards,

Richard Quadling.
0
 
Richard QuadlingSenior Software DeveloperCommented:
ammad,

http://www.javaworld.com/javaworld/javatips/jw-javatip94.html

gives a lot of useful info about this.

Regards,

Richard.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> ANy idea that client will get popup to save this file on his hard disk

You have to use:

response.setContentType ( "application/octet-stream" ) ; // or whatever you want. For unknown, you can use application/x-stream
response.setHeader ( "Content-disposition", "attachement; filename=\"Filename.extension\"" ) ;
0
Cloud Class® Course: C++ 11 Fundamentals

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

 
Richard QuadlingSenior Software DeveloperCommented:
attach e? ment

No e in the middle.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
As a matter of fact, if you are using IE 5 - the 'e' is there. There was a bug ;-) which they corrected in SP 2 for IE 5. IE 6 accepts the correct spelling "attachment". Netscape seems to accept both I guess. Not sure what the target browser is in this case ;-) I guess we should try both.
0
 
Richard QuadlingSenior Software DeveloperCommented:
Oh. That is AWFUL!!!

But, I suppose no worse that "referer" which seems is W3C wrong!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Many people can make spelling mistakes with referer ;-) it still 'looks' as though it is correct.

One can actually use the "User-Agent" request header to check what the client browser is and accordingly use "attachement" for some special cases and use "attachment" as the default ;-)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Any reason for the B grade? You can ask for more clarification if you want.
0
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.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now