标签:
本例子主要是处理request编码问题
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub final HttpServletRequest request1=(HttpServletRequest) request; request.setCharacterEncoding("utf-8"); //创建代理对象 HttpServletRequest p=(HttpServletRequest) Proxy.newProxyInstance(request1.getClass().getClassLoader(), new Class[]{HttpServletRequest.class} ,new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object returnValue=null; String m=method.getName(); if("getParameter".equals(m)){ //对get方法进行处理 String value=request1.getParameter(args[0].toString()); String me=request1.getMethod(); if("GET".equals(me)){ value=new String(value.getBytes("iso8859-1"),"utf-8"); } return value; }else{ returnValue=method.invoke(request1, args); } return returnValue; } }); System.out.println("过滤器执行"); chain.doFilter(p, response); }
标签:
原文地址:http://www.cnblogs.com/may12138/p/5538888.html