check this link. http://www.fawcette.com/javapro/2002_03/online/online_eprods/servlets_03_08/
> -----Original Message----- > From: Venkat Muthusamy [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, December 25, 2002 4:28 AM > To: [EMAIL PROTECTED] > Subject: attachment in jsp > > > Hi all, > I am trying to attach a pdf document in JSP. > > 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? > Any idea to attach a pdf using jsp is also welcome. > thanks > Venkat M > > The code is as follows. > > <%@ page import="java.io.*" %> > <% > > BufferedInputStream bis = null; > BufferedOutputStream bos = null; > > > try { > response.setContentType("application/pdf"); > response.setHeader("Content-disposition", "attachment; > filename=" + "JspSyntax.pdf"); > > String fileURL = "C:///jspsyntax.pdf"; > > OutputStream outp = response.getOutputStream(); > FileInputStream is = new FileInputStream(fileURL); > // Use Buffered Stream for reading/writing. > bis = new BufferedInputStream(is); > bos = new BufferedOutputStream(outp); > > byte[] buff = new byte[2048]; > int bytesRead; > > // Simple read/write loop. > while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { > bos.write(buff, 0, bytesRead); > } > } catch (java.net.MalformedURLException e) { > System.out.println("MalformedURLException."); > e.printStackTrace(); > } catch (final IOException e) { > e.printStackTrace(); > System.out.println("IOException."); > //throw e; > } finally { > > if (bis != null) > bis.close(); > if (bos != null) > bos.close(); > } > > %> > > ============================================================== > ============= > 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 > Disclaimer: This e-mail message along with any attachments is intended only for the addressee and may contain confidential and privileged information of GTL Limited. If the reader of this message is not the intended recipient, you are notified that any dissemination, distribution or copy of this communication is strictly prohibited. If you have received this message by error, please notify us immediately, return the original mail to the sender and delete the message from your system. =========================================================================== 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