tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: How can I refresh tomcat in the java code?
Date Thu, 03 Apr 2008 13:44:38 GMT
Hash: SHA1


Guilherme Orioli wrote:
| Didn't get it... it just doesn't work... what do I need to use instead of
| the response.redirect ?

These good folks are telling you to do something differently than you
are currently doing it.

Right now you are trying to:

1. generate your content
2. write the content to a file on the disk
3. redirect the user to the newly-generated file on disk

Everyone is telling you to:

1. generate your content
2. write the content out to the ServletOutputStream directly
~   (not to System.out, nor to a FileOutputStream)

No disk file; no redirect. Each request re-generates the content and
sends it back to the client (browser) as the response to the original

Let me lay it out for you. You currently have this code:

| try{
| ServletOutputStream sos = response.getOutputStream();
| pdfStream.writeTo(sos);
| System.out.println("pdsStream - "+pdfStream);
| response.sendRedirect("myPDF.pdf");
| sos.flush();
| sos.close();
| pdfStream.close();
| pdfStream = null;
| }catch(IOException e){
| e.printStackTrace();
| }
| return "";

You should change it to:

~    ServletOutputStream sos = response.getOutputStream();
~    pdfStream.writeTo(sos);
~    sos.flush();
~    sos.close();
~    pdfStream.close();
} catch(IOException e) {
~    e.printStackTrace();

~    response.sendError(HttpServletResponse.INTERNAL_SERVER_ERROR,
~                       e.getMessage());
return "";
/// ^^^ What is this?

I'm not sure why your method returns a String. There's no reason for it
to do so. Is this in a servlet? If it is, then you are going to run in
to trouble with the "request" and "response" objects being members of
the class. Two simultaneous requests will completely break your application.

You can simplify the code somewhat, as well as reducing the amount of
memory required to operate by eliminating your use of a
ByteArrayOutputStream. The only downside is that your servlet will not
be returning a Content-Length with the response (which isn't that big of
a deal).

- -chris

Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message