解决Tapestry5中文问题 (转)

注意要在工程里面要引入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);  
            }  
        };  
    }  


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值