DDR爱好者之家 Design By 杰米

定义一过滤器,实现Filtter接口

public class EncodingFilter implements Filter {

@Override
public void destroy() {
// TODO Auto-generated method stub

}

@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)resp;

request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");

chain.doFilter(req, resp);

}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub

}
}

web.xml文件中,配置过滤器

<filter>
 <filter-name>EncodingFilter</filter-name>
 <filter-class>pers.filter.EncodingFilter</filter-class>
 </filter>



<filter-mapping>
 <filter-name>EncodingFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>

以上这篇jsp用过滤器解决中文乱码问题的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米