On Tue, Dec 24, 2002 at 03:57:49PM -0700, Venkat Muthusamy wrote:
> I am trying to attach a pdf document in JSP.

     What do you mean you're trying to "attach" it?  Do you want the
PDF to come up in the user's browser window for viewing?  If so, just
put the PDF in a static file and redirect the user to it.  If you want
to force the user's browser to pop up the "Save As..." dialog, keep
reading:

> Whenever I access the jsp I am getting error in first time. After
> that it is working fine . Any idea.  While open the url when
> firsttime it is saying (you are downloading *.jsp) in file save
> popup and gives error.After that it shows (you are downloading
> *.pdf)Then it opens the pdf.  Is there a way to suppress this error
> or am i doing something wrong in the code?

     The code below looks basically right, comparing it to my notes
from when I wrote a servlet a few years ago to force a download.

     I don't recall any issue with the browser trying to download the
jsp.  There is an issue that the browser will assume the data file
being sent back is named the same as the page the browser requested.
The browser asks for "foo.jsp" and the server sends it a bunch of
binary data, it's going to naturally assume that data belongs in a
file named "foo.jsp".  You need to look at setting a
Content-Disposition header to set the filename, i.e.:

response.setHeader ("Content-Disposition", "attachment;  
filename=\"yourfilename.pdf\"");

     If that doesn't help, you might want to take a look at the
generated servlet code for this (i.e. use the -keepgenerated option
for your JSP compiler) and see if anything's tripping up the process
by sending extraneous data or headers back before your code gets to
setting headers and sending the binary data.

Steven J. Owens
[EMAIL PROTECTED]

"I'm going to make broad, sweeping generalizations and strong,
 declarative statements, because otherwise I'll be here all night and
 this document will be four times longer and much less fun to read.
 Take it all with a grain of salt." - Me at http://darksleep.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to