浏览 2872 次
锁定老帖子 主题:中文过滤器---Filter
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-12-24
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; /** * 编码过滤器, 默认UTF-8 * * @author linde13652 * */ public class EncodingFilter implements Filter { private String encoding = "UTF-8"; public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(this.encoding); chain.doFilter(request, response); } public void init(FilterConfig config) throws ServletException { String encoding = config.getInitParameter("encoding"); if (encoding != null && encoding.trim().length() > 0) { this.encoding = encoding; } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |