Hi,
Also do not forget to set the header so that the save as dialogue box is displayed in 
IE...For that you have to set the content-disposition header ..
following is the  code from our project..


Class  FileOpenAction{

        protected final void returnBinaryFile(
                HttpServletResponse response,
                String filename
                String saveAsName)
                throws FileNotFoundException, IOException {
                response.setContentType(mimeType);
                String fileExt = 
WebUtil.getFileExtensionFromMIMEType("application/pdf");
                setSaveAsHeader(response,saveAsName,fileExt);
                File file = new File(filename);
                response.setContentLength((int) file.length());

                FileInputStream in = new FileInputStream(file);
                OutputStream out = response.getOutputStream();
                byte[] buf = new byte[4096];
                int count = 0;

                while ((count = in.read(buf)) >= 0) {
                        out.write(buf, 0, count);
                }

                in.close();
                out.close();
        }

        public static void setSaveAsHeader(HttpServletResponse response,String 
saveAsFileName,String fileExt){
                if(saveAsFileName == null){
                        return;
                }
                //to get over a problem in browsers due to which the file name must 
have proper extension
                if((fileExt != null)|| (fileExt.length() !=0)){
                        int index1 = saveAsFileName.indexOf(fileExt.toUpperCase());
                        int index2 = saveAsFileName.indexOf(fileExt.toLowerCase());
                        if((index1 == -1) &&(index2 == -1)){
                                saveAsFileName = saveAsFileName + "." + fileExt;
                        }
                }
                response.addHeader("Content-Disposition", "attachment; filename=" + 
saveAsFileName ); 
        }       
}

Also another thought..Why use another servlet..Just use another action like we 
do..This way you can use all the existing framwroek..Like authorisation etc....

-----Original Message-----
From: Surachai Locharoen [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 24, 2003 10:41 PM
To: Struts Users Mailing List
Subject: Re: PDF file in browser


Additionally, In struts framework you have to reset request header before by
call


    request.reset();
    request.setContentType("application/pdf");
    request.setContentLength(byte.length);



----- Original Message -----
From: "Navjot Singh" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, December 23, 2003 9:53 PM
Subject: RE: PDF file in browser


> if you can reveal the location of the PDFs on your web server.
> Simply put your pdfs under a www/app.com/pdfs/*.pdf and give them links as
> you want.
>
> if you wish to maintain some security.
> 1. send a request to a servlet wit some pdf code or file name
> 2. open the given file from the file system whereever it is.
> 3. convert it into stream.
> 4. push the stream back to browser.
>
> note - must set the appropraite mime/type before you push the stream back.
> may be application/pdf or application/x-pdf
>
> HTH
> Navjot Singh
>
> >-----Original Message-----
> >From: vasudevrao gupta [mailto:[EMAIL PROTECTED]
> >Sent: Wednesday, December 24, 2003 10:50 AM
> >To: 'Struts Users Mailing List'
> >Subject: PDF file in browser
> >
> >
> >
> >
> >Hi All,
> >
> > I am using Struts frame work for our application with Web sphere
> >app server.
> >We have a some PDF files on the app server .When the user clicks on a
> >particular link on
> >the JSP page, we have show a pdf  file to the user in a new browser
> >window.
> >Can any one pls tell me the easier procedure to do this??
> >
> >Regards
> >VasudevRaoGupta
> >
> >
> >Confidentiality Notice
> >
> >The information contained in this electronic message and any
> >attachments to this message are intended
> >for the exclusive use of the addressee(s) and may contain
> >confidential or privileged information. If
> >you are not the intended recipient, please notify the sender at
> >Wipro or [EMAIL PROTECTED] immediately
> >and destroy all copies of this message and any attachments.
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to