javaee中的编码问题

来源:互联网 发布:apache johnzon 编辑:程序博客网 时间:2024/05/21 22:50

 

为了解决编码问题可以在BaseServlet中的service()方法中写:

request.setCharacterEncoding("utf-8");只能负责处理客户端请求的post()方法。Get()方法不能处理

request = new GetRequest(request);负责处理service()方法对客户端的反应。

为了解决对于get的方法的编码问题,可以使用装饰者模式,对客户端来的request对象进行包装封装成一个对request某些方法进行加强后的包装类,再在BaseServlet的service方法中进行判断,

if(request.getMethod().equalsIgnoreCase("post")){

                                          request.setCharacterEncoding("utf-8");

                            }elseif(request.getMethod().equalsIgnoreCase("get")){

                                          request= new GetRequest(request);

                            }

0 0
原创粉丝点击