jsp用过滤器解决中文乱码问题的方法
程序员文章站
2024-01-20 21:49:52
定义一过滤器,实现filtter接口
public class encodingfilter implements filter {
@override...
定义一过滤器,实现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用过滤器解决中文乱码问题的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。