myeclipse连接mysql数据库中文乱码问题
表单提交中文参数保存在数据库中时在数据库中显示成乱码了,然后如果从数据库获取中文到我的程序中依然是乱码,并且报空指针异常,请问怎么解决啊?(我用数据源方式连接的数据库)...
表单提交中文参数保存在数据库中时在数据库中显示成乱码了,然后如果从数据库获取中文到我的程序中依然是乱码,并且报空指针异常,请问怎么解决啊?(我用数据源方式连接的数据库)
展开
3个回答
2013-06-26
展开全部
action是get还是post、、 get的话好像头部设置一下编码方式就可以了、contentType="text/html;chartset=GBK" pageEncoding="GBK" post的话在处理页面写上、<%request.setCharacterEncoding("GBK"); %> 实在不行就弄个filter吧、、给你个代码、、去琢磨琢磨、、、这个是servlet、public class SetCharacterEncodingFilter implements Filter { protected FilterConfig filterConfig = null;
protected String encoding = ""; public void destroy() {
this.encoding = null;
this.filterConfig = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(this.encoding);
chain.doFilter(request, response);
} public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
}
这个是web.xml配置、<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>y2ssh.sg.common.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 应该能看懂吧、、、、、、 祝你好运、、、、
protected String encoding = ""; public void destroy() {
this.encoding = null;
this.filterConfig = null;
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(this.encoding);
chain.doFilter(request, response);
} public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
}
这个是web.xml配置、<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>y2ssh.sg.common.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 应该能看懂吧、、、、、、 祝你好运、、、、
2013-06-26
展开全部
MyEclipse默认编码是UTF-8,MySQL的默认编码也是UTF-8,在MyEclipse中执行SQL脚本,在MySQL中查询出的结果中文部分都是乱码,我已经设置了设置了下面的编码:
mysql> set character_set_client=utf8;
mysql> set character_set_connection=utf8;
mysql> set character_set_database=utf8;
mysql> set character_set_results=utf8;
mysql> set character_set_server=utf8;
mysql> set character_set_system=utf8;
mysql> set collation_connection=utf8;
mysql> set collation_database=utf8;
mysql> set collation_server=utf8;
mysql> set character_set_client=utf8;
mysql> set character_set_connection=utf8;
mysql> set character_set_database=utf8;
mysql> set character_set_results=utf8;
mysql> set character_set_server=utf8;
mysql> set character_set_system=utf8;
mysql> set collation_connection=utf8;
mysql> set collation_database=utf8;
mysql> set collation_server=utf8;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-26
展开全部
看数据库是XXX字符集的,然后获取时set names XXX
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询