Jfinal和httl整合

public class HttlRenderFactory implements IMainRenderFactory {

	public Render getRender(String view) {
		return new HttlRender(view);
	}

	public String getViewExtension() {
		return ".htm";
	}
}

public class HttlRender extends Render {

	private static final long serialVersionUID = 1012573049421601960L;
	private transient static final String encoding = getEncoding();
	private transient static final String contentType = "text/html;charset="
			+ encoding;

	public HttlRender(String view) {
		this.view = view;
	}

	public void render() {
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("request", request);
			map.put("response", response);
			response.setContentType(contentType);

			Template template = Engine.getEngine().getTemplate(view);
			template.render(map, response);
		} catch (Exception e) {
			throw new RenderException(e);
		}
	}
}

然后在Config中configConstant方法中添加:

me.setMainRenderFactory(new HttlRenderFactory());

在httl.properties中添加:

import.packages+=javax.servlet,javax.servlet.http
resolvers+=httl.spi.resolvers.ServletResolver
interceptors+=httl.spi.interceptors.ServletInterceptor
out.converters+=httl.spi.converters.ResponseOutConverter
import.variables+=HttpServletRequest request,HttpServletResponse response,HttpSession session,ServletContext application,Map cookie,Map parameter,Map header

参考了《httl和NUTZ整合》,感谢!

你可能感兴趣的:(jFinal,httl)