Hi

I don't know if this helps...But I have read somewhere, that you must set up
the content-length header of your response, when doing PDF streaming.

Just set it as the size of your FileStream (or another stream object)

Try it out..and let me know..





----- Original Message ----- 
From: "deepaksawdekar" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, March 10, 2004 6:07 AM
Subject: pdf file open.


Hi,
I am trying to open a pdf file. I am using servlet and struts in my
application. Everything is working fine except it ask me two times do you
want to open or save the file, once for the file whoes name is session id
and second time for the actual file.
Am i doing some thing wrong.
Please help me


Servelet code is as follows

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {

        //Method name
        final String METHOD_NAME = CLASS_NAME.concat(".doGet()");

        String sessionId =
request.getParameter(GUIConstants.USER_SESSION_ID);
        String encodefileName =
            request.getParameter(GUIConstants.USER_FILE_NAME);
        String fileName = new String();
        try {
            fileName =
                URLDecoder.decode(encodefileName,
GUIConstants.CHAR_ENCODING);
        } catch (Exception ex) {
            LOGGER.error(METHOD_NAME, ex);
        }
        HttpSession session = request.getSession();

        if (!session.getId().equals(sessionId)) {
            // Don't do anything - just return
            //response.sendRedirect(GUIConstants.LOGIN_URL);
            return;
        }

        LOGGER.debug("File Name " + fileName);
        int dot = fileName.lastIndexOf(CommonConstants.DOT) + 1;
        if(fileName.substring(dot).equalsIgnoreCase(CommonConstants.PDF)) {
        response.setContentType(GUIConstants.PDF_CONTENT_TYPE);
        } else {
        response.setContentType(GUIConstants.CONTENT_TYPE);
        }
        response.setHeader(
            GUIConstants.CONTENT_DIS,
            GUIConstants.CONTENT_ATT + "\"" + fileName + "\"");

        try {
            String filePath =
                GetProperties.getValue(
                    PropertiesFileConstants.PMP_PROP_FILE_PATH,
                    CommonConstants.DOCUMENT_LOCAL_STORE_PATH_FOR_VIEWING);
            ServletOutputStream out = response.getOutputStream();
            String fullFilePath = filePath + File.separator + fileName;
            FileInputStream fin = new FileInputStream(new
File(fullFilePath));
            byte[] buf = new byte[GUIConstants.FILE_SIZE];
            int len = 0;
            while ((len = fin.read(buf)) != -1) {
                out.write(buf);
            }
            out.flush();
            fin.close();

        } catch (Exception e) {
            //e.printStackTrace();
            LOGGER.error(e.getMessage(), e);
        }

    }

    /**
     * @param req HttpServletRequest
     * @param res HttpServletResponse
     * @throws ServletException servlet exception
     */
    public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws ServletException {
        doGet(req, res);
    }


Thanks and Regards
Deepak.

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