Problem :-

                        Downloading  a file from WebServer(Linux) to Windows
Client using JSP.
                                While downloading a file from webserver to
client it is downloading properly  with the entire content but the size of
the downloaded file is more with the original one. It is not downloading
with the original size.

                                For reference code segment is also attached
below, which is used to download a file.

                        String fileURL =
"http://"+SWebserverHost+"/download/"+ SDocName;

                        BufferedInputStream bis = null;
                        BufferedOutputStream bos = null;

                        try
                        {
                                URL url = new URL( fileURL );
                                URLConnection conn = url.openConnection();
                                String SContentType = conn.getContentType();
                                response.setContentType(SContentType);
                                bis = new
BufferedInputStream(conn.getInputStream());
                                // Use Buffered Stream for reading/writing.
                                int isize = bis.available();
                                int bytesRead = 0;

response.setHeader("Content-disposition","attachment;filename="+SDocName);
                                // Simple read/write loop.
                                while( (bytesRead = bis.read()) != -1)
                                {
                                        ServletOutputStream outStream =
response.getOutputStream();
                                        outStream.write(bytesRead);
                                        outStream.flush();
                                }
                        }
                        catch(final MalformedURLException e)
                        {
                                System.out.println (
"MalformedURLException." );
                                out.println(e);
                                throw e;
                        }
                        catch(final IOException e)
                        {
                                System.out.println ( "IOException." );
                                out.println(e);
                                throw e;
                        }
                        finally
                        {
                                if (bis != null)
                                bis.close();
                                if (bos != null)
                                bos.close();
        }
*********************************************************************
Disclaimer: The information in this e-mail and any attachments is
confidential / privileged. It is intended solely for the addressee or
addressees. If you are not the addressee indicated in this message, you may
not copy or deliver this message to anyone. In such case, you should destroy
this message and kindly notify the sender by reply email. Please advise
immediately if you or your employer does not consent to Internet email for
messages of this kind.
*********************************************************************

===========================================================================
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