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
Solved

TEXT Data Download in Browser.

Posted on 2006-06-19
9
221 Views
Last Modified: 2010-03-31
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
Comment
Question by:ammad
  • 4
  • 4
9 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16933854
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16933883
ammad,

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

gives a lot of useful info about this.

Regards,

Richard.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 125 total points
ID: 16934184
>> 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16934190
attach e? ment

No e in the middle.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16934204
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16934222
Oh. That is AWFUL!!!

But, I suppose no worse that "referer" which seems is W3C wrong!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16934242
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 17120627
Any reason for the B grade? You can ask for more clarification if you want.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 34
login form jsp example 2 37
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 30
Java Eclipse Loop 3 20
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

856 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