Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struts and XSL Transformation

Status
Not open for further replies.

LuckyKoen

Programmer
Feb 14, 2005
57
BE
I have a servet that transforms an xml and xsl file into a new html page. This new html page is generated as an output stream and shown in my browser. I want to use this servlet in a struts application and I have placed my transformation code in an action method.

It seems however that the execute method always needs to return an ActionForward. Since my code generates a new html page right after the transformation I am a bit unsure what to do with the return ActionForward. The result of my transformation is shown correctly but I still get an error : Cannot forward after response has been committed.

Here is the code :

Code:
public ActionForward execute (  		
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {
      
        
	try {
		PrintWriter out;
		out = response.getWriter();
		
	        File xmlFile = new File ("url...");
	        File xslFile = new File ("url...");
	        
	        Transformer t = null;
	        TransformerFactory tFactory = TransformerFactory.newInstance();
	        
	        Source xmlSource = new StreamSource(xmlFile);
	        Source xslSource = new StreamSource(xslFile);
        
		t = tFactory.newTransformer(xslSource);    
		StreamResult result = new StreamResult(out);
			
		t.transform(xmlSource, result);		
	}
	
	catch (TransformerException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}  
		   
	catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return mapping.findForward(FORWARD_calendar);
}

Is there a way to tell struts that I don't want to forward anything or do I need to use something else than a StreamResult ?
 
Hi,

You can return null, but before that just make sure you have send the response back;

Cheers
Venu
 
Thanks for the quick reply Venur, I don't get that error anymore. Struts are new to me though and I am still wondering if I am "supposed" to program a struts application like this. It doesn't exactly look like a clean way to fix things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top