使用jfinal 默认模板, render页面时,模板加载了两次,请问这是怎么回事??
是用handle拦截所有页面,然后render的
public class PageHandler extends Handler { @Override public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) { String regHtml = "(.*/.*\\.html)"; if(target.matches(regHtml)) { RenderManager.me().getRenderFactory().getRender(target).setContext(request, response).render(); } } }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> demo! </body> </html>
最后展示的效果是下面这样的...
demo! demo!
这是浏览器展示的代码
<html><head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> demo! <meta charset="UTF-8"> <title>Insert title here</title> demo! </body></html>
项目:JFinal
if(target.matches(regHtml)){
RenderManager.me().getRenderFactory().getRender(target).setContext(request, response).render();
isHandled[0] = true;
} else {
next.handle(target, request, response, isHandled);
}