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

N

Nishi Bhonsle

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();
}
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top