81,092
社区成员
发帖
与我相关
我的任务
分享
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //设置请求编码 HttpServletRequest req=(HttpServletRequest)request; if(req.getMethod().equalsIgnoreCase("post")){ req.setCharacterEncoding("UTF-8"); }else{ Map map=req.getParameterMap(); if(map.size()>0){ Collection values=map.values(); Iterator it=values.iterator(); while (it.hasNext()) { String[] object = (String[]) it.next(); for (int i = 0; i < object.length; i++) { object[i]=new String(object[i].getBytes("iso8859-1"),"UTF-8"); } } } } //设置响应编码 response.setContentType("text/html;charset=UTF-8"); chain.doFilter(request, response); }