JspFactory jspFactory = JspFactory.getDefaultFactory();
PageContext pageContext = jspFactory.getPageContext(this, request, response, null, true, 8192, true);
// put the new PageContext into ActionContext
ActionContext actionContext = ActionContext.getContext();
actionContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
/*
* Must put the stack into HttpServletRequest, because the WebWork JSP
* Taglib will use it to judge whether there are some errors in stack.
*/
OgnlValueStack stack = ActionContext.getContext().getValueStack();
//request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,
// stack);
//Moved to WebWorkPortlet doService()
VelocityManager velocityManager = VelocityManager.getInstance();
Context resultContext = velocityManager.createContext(stack, request, response);
response.setContentType("text/html");
try {
String location = (String) ActionContext.getContext().get("template");
Template template = velocityManager.getVelocityEngine().getTemplate(location);
Writer writer = pageContext.getOut();
template.merge(resultContext, writer);
writer.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
// perform cleanup
jspFactory.releasePageContext(pageContext);
actionContext.put(ServletActionContext.PAGE_CONTEXT, oldPageContext);
}
}