package com.newer.filter;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class EcodeFilter implements Filter {
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest request =(HttpServletRequest)arg0;
if(request.getMethod().equalsIgnoreCase("get")){
Map map=request.getParameterMap();
Iterator it=map.values().iterator();
while(it.hasNext()){
String[]str=(String[])it.next();
for(int i=0;i<str.length;i++){
str[i]=new String(str[i].getBytes("iso-8859-1"),"utf-8");
}
}
}else{
arg0.setCharacterEncoding("UTF-8");
}
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}