java 汉字乱码问题解决方法
下面关于网页特效p/网页特效p.html target=_blank >jsp教程汉字乱码问题我们是做了一个过滤器,然后到web中配置一下,这样很好的解决了jsp中汉字编码问题哦。
*/
public class characterfilter implements filter {
public void destroy() {
}
public void dofilter(servletrequest request, servletresponse response,
filterchain filter) throws ioexception, servletexception {request.setcharacterencoding("utf-8");
response.setcharacterencoding("utf-8");
filter.dofilter(request, response);
}public void init(filterconfig arg0) throws servletexception {
}
}
%>
再到 web配置中www.111com.net
characterfilter
org.shopping.uitl.characterfilter
再来看一下官方的对汉字乱码处理方法吧。mb.111com.net<%
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;
/**
* 过滤器,设置文字编码格式
*/
public class setcharacterencodingfilter implements filter {protected string encoding = null;
protected filterconfig filterconfig = null;
protected boolean ignore = true;
public void destroy() {
this.encoding = null;
this.filterconfig = null;}
public void dofilter(servletrequest request, servletresponse response,
filterchain chain)
throws ioexception, servletexception {if (ignore || (request.getcharacterencoding() == null)) {
string encoding = selectencoding(request);
if (encoding != null)
request.setcharacterencoding(encoding);
}chain.dofilter(request, response);
}
public void init(filterconfig filterconfig) throws servletexception {
this.filterconfig = filterconfig;
this.encoding = filterconfig.getinitparameter("encoding");
string value = filterconfig.getinitparameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsignorecase("true"))
this.ignore = true;
else if (value.equalsignorecase("yes"))
this.ignore = true;
else
this.ignore = false;}
protected string selectencoding(servletrequest request) {
return (this.encoding);
}
}
%>
过滤器在xml中的配置:
xml code
setcharacterencodingfilter
包名.setcharacterencodingfilter
encoding
utf-8
setcharacterencodingfilter
/*
迷雾城堡免广告 最新版v0.1.30
迷雾城堡免广告是一款非常好玩的模拟建造类手游,玩家无需看广告
鉴车大师免广告 安卓版v1.2.2
鉴车大师免广告是一款非常好玩的模拟类手游,玩家在游戏中不用看
从前有条街 安卓最新版v1.5
从前有条街是一款非常好玩的模拟经营类手游,玩家在游戏中将会进
我的世界源之界冰火魔龙 最新版v阿夜整合
我的世界源之界冰火魔龙模组整合包是一款像素风格的沙河模拟生存
假面骑士创骑腰带模拟器 安卓版v6
假面骑士创骑腰带模拟器是一个专为喜欢假面骑士的用户打造的变身