Rendering a page handling a File Download Dialog causes page state to belost

Discussion in 'Java' started by Nishi Bhonsle, Feb 25, 2004.

  1. On a webserver, I have a set of client pages that are based on XML technology with events triggered on each action, these events are written in java.
    One of the pages say A has a link say link1 which when clicked prompts for a File Save As Dialog box. I observe that when the file is saved and control is returned back to the page A, the state of that page is lost.

    ie I have to login some credentials(such as username/passwd) in order to be directed to page A, those credentials are saved on Page A. There are other links on Page A which when clicked get directed to different other pages and it is possible to come back to Page A without losing the state. The state or the session information is lost only in the case when the File Save As Box is called.
    Does anyone know of how I could save the session state or preserve the session state through java?

    The java class FileDownloadRenderer supports streaming binary and text.It has methods to handle a given input stream, the stream
    will be closed once the page has rendered and for a given reader, the mimeType should include the character set encoding used, if applicable. The reader will be closed once the page has rendered.


    The following code renders the page A

    public void renderPage(BajaContext context,Page page) throws IOException, ServletException
    {
    System.out.println("in render page");

    if ((_stream == null) && (_reader == null))
    {
    //BajaHttpUtils.sendNotFoundError(context);
    return;
    }
    else
    {
    HttpServletResponse response = context.getServletResponse();

    response.setContentType(_mimeType);
    if (_fileName != null)
    {
    response.setHeader("Content-disposition",
    "attachment; filename=" + _fileName);
    }

    if (_size >= 0)
    {
    response.setContentLength(_size);
    }

    if (_stream != null)
    {
    OutputStream out = response.getOutputStream();
    try
    {
    byte[] buffer = new byte[8192];
    int bytesRead = 0;
    while (bytesRead >= 0)
    {
    bytesRead = _stream.read(buffer);
    if (bytesRead > 0)
    out.write(buffer, 0, bytesRead);
    }
    }
    finally
    {
    out.close();
    _stream.close();
    }
    }
    else
    {
    Writer out = response.getWriter();
    try
    {
    char[] buffer = new char[4096];
    int charsRead = 0;
    while (charsRead >= 0)
    {
    charsRead = _reader.read(buffer);
    if (charsRead > 0)
    out.write(buffer, 0, charsRead);
    }
    }
    finally
    {
    out.close();
    _reader.close();
    }
    }
    }
    }
     
    Nishi Bhonsle, Feb 25, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Osa
    Replies:
    0
    Views:
    640
    Xavier Osa
    Jan 9, 2004
  2. Daniel Cardoso
    Replies:
    1
    Views:
    783
    Daniel Cardoso
    Sep 24, 2004
  3. Ryan Taylor
    Replies:
    2
    Views:
    959
    Ryan Taylor
    Nov 10, 2004
  4. Brett  Kelly
    Replies:
    1
    Views:
    686
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
  5. Neil Rossi
    Replies:
    5
    Views:
    550
    Neil Rossi
    Feb 7, 2006
Loading...

Share This Page