동적 프 록 시 를 사용 하여 get 매개 변수 중국어 혼란 해결

public class RequestHandler implements InvocationHandler {
	HttpServletRequest request;
	public RequestHandler(HttpServletRequest request){
		this.request=request;
		
	}
	
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		// TODO Auto-generated method stub
		
	 	Object result=method.invoke(request, args);
	 	if(method.getName().equals("getParameter")){
                     //                 
	 		if(result != null){
                            result =new String(((String)result).getBytes("ISO-8859-1"),"UTF-8");
                        }
                }
		return result;
	}
}

 웹.xml 에 필 터 를 설정 합 니 다.키 코드 는 다음 과 같 습 니 다.
 
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		InvocationHandler handler = new RequestHandler((HttpServletRequest)arg0);
		HttpServletRequest request=(HttpServletRequest)Proxy.newProxyInstance(arg0.getClass().getClassLoader(), arg0.getClass().getInterfaces(), handler);
		
		arg2.doFilter(request, arg1);
	}

 위 프로그램의 차단 처 리 를 통 해 action 에서 request.getParameter 방법 으로 인 자 를 가 져 올 때 정확 한 디 코딩 값 을 얻 을 수 있 습 니 다.

좋은 웹페이지 즐겨찾기