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 :
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 ?
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 ?