(1)在连接数据库的url后面加上:?useUnicode=true;characterEncoding=gbk;
(2)在mysql的my.ini文件中加入default-character-set=gbk
(2)在mysql的my.ini文件中加入default-character-set=gbk
解决方案 »
- 求助,spring3 注解事务 回滚失败
- 局域网内能够使用google map api吗?
- spring中集成Hibernate的配置文件问题,大家请帮忙看一下!
- js 问题!!!
- 查询页面保留以前的查询条件,为什么不是空页面,请问该怎么解决?
- 关于无刷新请求服务器资源的方法总结.
- 如何用AJAX 获取后台验证码问题(急啊)
- 请问一下String类是不是有长度限制,为多少,如果超过怎么办?
- 关于APACHE和TOMCAT结合使用的问题?
- 在jsp的网页上提供一个logout方法回到首页。用什么方法来实现相当于关闭窗口后重新打开一个首页。即关闭原页的session,无法后退。
- JSP内部对象详解
- jsp新手,问题急,进来的都是好人
加gb2312也没有用。my.ini这个文件在什么地方?
是在mysql中的目录下吗?我要上传到我购买的虚拟目录下,这样my.ini这个文件我可以更改吗?
好像不行吧。
我刚试了一下,不好用,还是乱码。
(2)在mysql的my.ini文件中加入default-character-set=gbk
(3)看看你的数据库表的字集集,如果不是中文字符集修改一下。可能是utf8或是其它的。
alert table ........
不知如何操作。
我如何来解决我的mysql中文问题。是不是服务器端已经解决完了。
还是需要自己来设置.
public class SetCharEncode 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 {
String encoding = selectEncoding(request);
request.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+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);
}
}
在web.xml配置:
<filter>
<filter-name>setchar</filter-name>
<filter-class>com.xdg.filter.SetCharEncode</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setchar</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>如果这样还有乱码,那就是奇迹了。这个方法我可是从来没有公布过的,而且最简单。算你走运。自己研究出来的。
谢谢楼上的了。我是在配置jive论坛出现的乱码问题。
按你的方法回去试一下。
看看是否能成功。加一个过滤器。
public class SetCharEncode 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 {
String encoding = selectEncoding(request);
request.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+encoding.toLowerCase());//这个地方必须是小写,我也不知道为什么
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);
}
}
我试过来。
必须要页面上要加上8859_1这个字符编码才可以通过。测试环境windows2000 server mysql4.1
只有加8859_1才可以。
只需要把默认字符集设置为gbk,
页面用8859_1即可通过测试。