A
Alex Molochnikov
Our servlet must generate a report in PDF format, and send it to a browser.
I've run into the following two problems:
1. If the generated byte array is streamed to the browser like this (from
the doPost() method):
byte[] bArray = <PDF byte content>
response.setContentType("application/pdf");
response.setContentLength(bArray.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(bArray);
sos.flush();
the file promptly appears in the browser, but if the user presses the back
button, followed by the forward button (jump to the previous page, and then
back to the report page), the report page becomes blank. This happens
because the browser calls doGet() servlet's method (which is not wired up to
produce the report), instead of using the cached page. This happens in IE
only; Netscape and Firefox work fine.
2. I attempted to solve this problem by saving the PDF data in a temporary
file, and serving the file, instead of the data stream. This worked in
Tomcat, where I can designate a directory that is part of the app context
hierarchy (i.e. is visible as a URL) by placing the directory into the
webapps/<app name> folder.
But now the app is deployed as an EJB in JBoss, and there is no location in
JBoss that could be used as a repository of dynamically created files to be
served from it. I suppose, getting into the app server's filesystem is so
much against the grain of EJB, that - unlike Tomcat - JBoss does not have
any notion of the user-managed file hierarchy.
Has anyone been confronted with such problems? Any clues will be
appreciated.
Alex Molochnikov
Gestalt Corporation
I've run into the following two problems:
1. If the generated byte array is streamed to the browser like this (from
the doPost() method):
byte[] bArray = <PDF byte content>
response.setContentType("application/pdf");
response.setContentLength(bArray.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(bArray);
sos.flush();
the file promptly appears in the browser, but if the user presses the back
button, followed by the forward button (jump to the previous page, and then
back to the report page), the report page becomes blank. This happens
because the browser calls doGet() servlet's method (which is not wired up to
produce the report), instead of using the cached page. This happens in IE
only; Netscape and Firefox work fine.
2. I attempted to solve this problem by saving the PDF data in a temporary
file, and serving the file, instead of the data stream. This worked in
Tomcat, where I can designate a directory that is part of the app context
hierarchy (i.e. is visible as a URL) by placing the directory into the
webapps/<app name> folder.
But now the app is deployed as an EJB in JBoss, and there is no location in
JBoss that could be used as a repository of dynamically created files to be
served from it. I suppose, getting into the app server's filesystem is so
much against the grain of EJB, that - unlike Tomcat - JBoss does not have
any notion of the user-managed file hierarchy.
Has anyone been confronted with such problems? Any clues will be
appreciated.
Alex Molochnikov
Gestalt Corporation