, , , , , , .
, , , sitemesh.
, Struts2, .
struts JSP/freemarker/speed html, . JSP - , , org.apache.struts2.views.freemarker.FreemarkerResult class, html-, template.process(model, writer);. ServletActionContext.getResponse().getWriter();
, html , , ServletActionContext.getResponse().getWriter().toString() //This does not work out of box. toString() , ResponseWrapper - html . See- .
html struts 2. , , . , , struts2
public class DecoratorInterceptor implements Interceptor {
public String intercept(ActionInvocation invocation) throws Exception {
final ActionContext context = invocation.getInvocationContext ();
HttpServletResponse responseParent = (HttpServletResponse)
context.get(ServletActionContext.HTTP_RESPONSE);
CharResponseWrapper wrapper = new CharResponseWrapper(responseParent);
ServletActionContext.setResponse(wrapper);
String result = invocation.invoke();
String htmlReturned = wrapper.toString();
String modifiedhtml = pushintoMemCache(htmlReturned );
CharArrayWriter car = new CharArrayWriter();
car.write(modifiedhtml );
PrintWriter out = responseParent.getWriter();
out.write(car.toString());
out.flush();
}
@Override
public void destroy() {
}
@Override
public void init() {
}
}