package com.luojin.web.filter;java
import java.io.IOException;web
import javax.servlet.Filter;app
import javax.servlet.FilterChain;ide
import javax.servlet.FilterConfig;字體
import javax.servlet.ServletException;url
import javax.servlet.ServletRequest;spa
import javax.servlet.ServletResponse;utf-8
public class FilterOne implements Filter{get
String encoding;servlet
//要消耗了
public void destroy() {
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
req.setCharacterEncoding(encoding);
resp.setCharacterEncoding(encoding);
chain.doFilter(req, resp);
}
//在響應前調用
public void init(FilterConfig config) throws ServletException {
encoding =config.getInitParameter("encoding");
}
}