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

Reply via email to