tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guilherme Orioli" <gui.ori...@gmail.com>
Subject Re: How can I refresh tomcat in the java code?
Date Thu, 03 Apr 2008 17:00:40 GMT
Christopher,

You got it right. I was trying to generate the content, write it into server
disk and redirect it to the user.

Everyone recomended me to generate it and send it as a response.
If that's the only option, I can accept that. If there's a way to refresh
the content under tomcat server folder, it would be better.

The problem with the recomended option is: It doesn't send the content to be
downloaded.
The system.out was just a test to see if the file was generated correctly.
It seems to be, since it prints tons of unknown chars. ^^
What this code I sent previously tries to do is:
1) Generate the pdf report (working fine)
2) Create a ByteArrayOutputStream with it (working fine)
3) Show it to be downloaded by the user (not working)

This code is located on a managed bean. The method is invoked when a
h:commandButton is pressed. That's why I return a String.

Hope you guys can help me now. Sorry for the english. I finished my course
four years ago and haven't practiced since then...

Gui Orioli.

2008/4/3, Christopher Schultz <chris@christopherschultz.net>:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Guilherme,
>
> 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
> request.
>
> 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:
>
> try{
> ~    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
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkf030UACgkQ9CaO5/Lv0PAZUgCdFrgxEz2Ni1O7TTxcEWqvYyXN
> TzAAmwRB3Oau5Q4BMOr2/1YpamUXSyz+
> =bmNA
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message