You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mazza, Glen R, PERSCOM" <Gl...@hoffman.army.mil> on 2002/08/22 18:10:03 UTC

response.reset() causing Tomcat/Struts messages to appear twice.

Hello,

Within an Action subclass, calling Response.reset() within my Action
subclass is causing logging information to appear twice in my Tomcat window
(I'm running Struts 1.1b and Tomcat 4.1.9):  

[INFO] RequestProcessor - -Processing a 'GET' for path '/retrieveitem'
[INFO] RequestUtils - - Looking for ActionForm bean instance in scope
'request' under attribute key 'retrieveItemForm'
[INFO] building formatting object tree
[INFO] [1]
[INFO] [2]
[INFO] Parsing of document complete, stopping renderer
[INFO] RequestProcessor - -Processing a 'GET' for path '/retrieveitem'
[INFO] RequestUtils - - Looking for ActionForm bean instance in scope
'request' under attribute key 'retrieveItemForm'
[INFO] building formatting object tree
[INFO] [1]
[INFO] [2]
[INFO] Parsing of document complete, stopping renderer

I'm generating a PDF document via FOP and writing out the response
"manually" in my Action subclass.  Prior to doing this, I need to call
Response.reset() so the PDF document will pop up in the browser instead of a
file download occurring. (If I don't call response.reset(), no duplicate
output in the logging occurs).

I'm unsure if this is a minor Struts/Tomcat logging error which causes the
output to appear twice--or, indeed, my PDF creation code is actually
occuring twice.  I believe it's the former--here's my code:

public class RetrieveItemAction extends Action {
   public ActionForward execute( ActionMapping mapping,
     ActionForm form, HttpServletRequest request, HttpServletResponse 
response)
     throws Exception {

	Log log = LogFactory.getLog( RetrieveItemAction.class );
	
	HttpSession session = request.getSession();
	
	// reset the response
	response.reset();
	response.setContentType("application/pdf");
	ServletOutputStream out = response.getOutputStream();
	
	try 
	{
		PDFDocumentService pdfDS = new PDFDocumentService();
		ByteArrayOutputStream baos =
pdfDS.getPDFDocument("DocName");
		byte[] content = baos.toByteArray();
		response.setContentLength(content.length);
		out.write(content);
		out.flush();
		out.close();
	}
	catch (Exception e)
	{
		if (log.isInfoEnabled()){
			log.info("error: " + e.getMessage());
		}
	}
	return null;
}
}

Any idea where the problem might be?

Thanks,
Glen

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>