注意要在工程里面要引入serlet-api.jar,否则编译不过去。
经测试,可以使用中文的html模板,表单输入的中文可以正常显示。
Just add this to your AppModule:
java 代码
//显示CJK(中文)页面
public static PageResponseRenderer decoratePageResponseRenderer(
@InjectService("PageMarkupRenderer")
final PageMarkupRenderer markupRenderer,
@InjectService("MarkupWriterFactory")
final MarkupWriterFactory markupWriterFactory, final Object delegate) {
return new PageResponseRenderer() {
public void renderPageResponse(Page page, Response response)
throws IOException {
MarkupWriter writer = markupWriterFactory.newMarkupWriter();
markupRenderer.renderPageMarkup(page, writer);
PrintWriter pw = response
.getPrintWriter("text/html; charset=GBK");
writer.toMarkup(pw);
pw.flush();
}
};
}
// 表单输入的CJK(中文)支持
public void contributeRequestHandler(
OrderedConfiguration configuration,
@InjectService("EncodingFilter")
RequestFilter encodingFilter) {
configuration.add("EncodingFilter", encodingFilter);
}
public RequestFilter buildEncodingFilter(@InjectService("RequestGlobals")
final RequestGlobals requestGlobals) {
return new RequestFilter() {
public boolean service(Request request, Response response,
RequestHandler handler) throws IOException {
requestGlobals.getHTTPServletRequest().setCharacterEncoding(
"GBK");
return handler.service(request, response);
}
};
}