Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 66872 invoked from network); 3 Apr 2008 13:38:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Apr 2008 13:38:23 -0000 Received: (qmail 73114 invoked by uid 500); 3 Apr 2008 13:38:11 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 73096 invoked by uid 500); 3 Apr 2008 13:38:11 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 73085 invoked by uid 99); 3 Apr 2008 13:38:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2008 06:38:11 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [74.54.141.23] (HELO mail.writingshow.com) (74.54.141.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2008 13:37:19 +0000 Received: from cpe-75-82-230-88.socal.res.rr.com ([75.82.230.88] helo=[192.168.1.106]) by mail.writingshow.com with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.67) (envelope-from ) id 1JhPfS-00027G-Bt for users@tomcat.apache.org; Thu, 03 Apr 2008 08:39:50 -0500 Message-ID: <47F4DDA0.1080304@compulsivecreative.com> Date: Thu, 03 Apr 2008 06:37:36 -0700 From: Alan Chaney Reply-To: alan@compulsivecreative.com Organization: Paula Hollywood, Inc. User-Agent: Thunderbird 1.5.0.14ubu (X11/20080306) MIME-Version: 1.0 To: Tomcat Users List Subject: Re: How can I refresh tomcat in the java code? References: <3a095c4a0804020755w3837b795pad23713c0054df9a@mail.gmail.com> <26248.170.201.180.136.1207152219.squirrel@webmail.chiron.lunarpages.com> <3a095c4a0804021018hf24fd2tf3aceb4341527da2@mail.gmail.com> <2828B04F0113CD468E6D1D51DF4362A4058B0041@USEA-EXCH2.na.uis.unisys.com> <46958.170.201.180.136.1207157553.squirrel@webmail.chiron.lunarpages.com> <2828B04F0113CD468E6D1D51DF4362A4058B00DC@USEA-EXCH2.na.uis.unisys.com> <3a095c4a0804021121r23f322a3s710928989f38ea91@mail.gmail.com> <3a095c4a0804021135v71764035o9ebca437b6eb7cff@mail.gmail.com> <47F3EEB6.7040403@compulsivecreative.com> <3a095c4a0804030451x76c80f0fy1c38f198ff7ccb82@mail.gmail.com> In-Reply-To: <3a095c4a0804030451x76c80f0fy1c38f198ff7ccb82@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org . Hi Guilherme I can see that English isn't your first language and I have a lot of respect for anyone who is trying to work on technical things in a foreign language - I could never do it! To help our communication I have tried to explain below what I think it is that you are trying to do. I may have misunderstood what it is that you are doing so I apologize if what I am saying is wrong. I've joined this thread a bit late, but looking at the previous emails it seems to me that your need is that a user should be able to download a pdf file which has been generated by your server? This is 'dynamic content'. The server responds to the request for a file by creating an OutputStream of pdf data Your use case is that the user clicks on a link in a web page and the PDF file appears in their browser? Here's what I would expect the sequence of events to be: 1. The user clicks on the link in the browser. The link has as its href for example "www.mycompany/xyz.pdf" 2. The browser generates an http GET request with the url www,mycompany/xzy.pdf and sends it out over the net. 3. Your container detects this request, looks up the appropriate servlet in its web.xml and calls the HttpServlet 'doGet' method. 4. Your servlet responds to this request and generates the pdf in a temporary file. 5. You set any response headers that you need to set. 6. You read the temporary file as a byte InputStream and write this to the servlet OutputStream. 7. The container takes the data from the output stream and transmits across the wire back to the browser. It inserts any headers you have specified (and a few others) at the beginning. 8. You return from the doGet. That's it. Done! So the stream of data which is returned as the response to .../xyz.pdf IS the data you want displayed. You don't need to send a redirect to xyz.pdf because you have already responded to the request. The exact point at which the container (Tomcat) starts to transmit data is up to the container. You can force it to send data by issuing a 'flush'. However, once it has started to respond to the specific request you cannot issue things like a redirect. I'm simplifying a bit here. Looking at your code there doesn't appear to be the doGet method - I assumed initially that you were calling your class from within the doGet of a servlet. Is this the case? Have you checked the tomcat logs? I would have expected the server to have thrown an exception when you attempted to send a redirect after you have already written data. Guilherme Orioli wrote: > Didn't get it... it just doesn't work... what do I need to use instead of > the response.redirect ? > > 2008/4/2, Alan Chaney : >> You don't need the redirect. The response to the request IS the pdf file. >> >> HTH >> >> >> Guilherme Orioli wrote: >> >>> It just doesn't show the Download dialog on the screen when i click the >>> button... >>> >>> 2008/4/2, Guilherme Orioli : >>> >>>> ok... here's what i'm doing... in system out, something like a pdf >>>> file is >>>> printed... it� probably there... just don't know how to show it from >>>> the >>>> button i'm clicking on: >>>> >>>> public String geraReportBois(){ >>>> try{ >>>> >>>> //Generating the report >>>> String caminho_arquivo = new File("").getAbsolutePath() + >>>> "/workspace/safeTrace/WebContent/reports/cliente/frigorifico/"; >>>> String nome_arquivo = "reportBois.jasper"; >>>> JasperReport jasperReport = >>>> (JasperReport)JRLoader.loadObject(caminho_arquivo + nome_arquivo); >>>> Map parameters = new HashMap(); >>>> parameters.put("Caminho", caminho_arquivo); >>>> JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, >>>> parameters, this.getRelatorioBois()); >>>> >>>> >>>> //---------------------------------------------------------------------------------- >>>> >>>> //Exporting to File (outputStream) >>>> ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); >>>> JasperExportManager.exportReportToPdfStream(jasperPrint, pdfStream); >>>> >>>> HttpServletResponse response = (HttpServletResponse) >>>> FacesContext.getCurrentInstance().getExternalContext().getResponse(); >>>> response.setContentType("application/pdf"); >>>> response.setHeader("Content-Disposition", "inline; >>>> filename=myPDF.pdf"); >>>> response.setContentLength(pdfStream.size()); >>>> 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 ""; >>>> >>>> }catch(JRException e){ >>>> System.out.println("entrou no catch geraReportBois"); >>>> >>>> e.printStackTrace(); >>>> } >>>> return null; >>>> } >>>> >>>> >>>> >>>> >>>> >>> >>> >> --------------------------------------------------------------------- >> 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 >> >> > > !DSPAM:47f4c55058681264652389! > --------------------------------------------------------------------- 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