不是jsp就是java程序,网上提供的方法太多了,但是好像都不行
改set name gbk
很多,很多
希望真正懂的人提供经典的方法。
改set name gbk
很多,很多
希望真正懂的人提供经典的方法。
解决方案 »
类似问题 »
- mysql 的Navicat for MySQL链接
- 奇怪了,单独操作一个20多行的表也会进入慢查询?
- 多列索引中的一列自增 在mysql 5.5.17执行不了
- MySQL 组合键怎么写, 谢谢
- mysql5 查询的问题,可以这样写吗?
- mysql中,group by分类汇总时,多行记录怎么进行拼接?
- 关于mysql_stmt_prepare()的错误
- 请问:在MSSQL中能不能通过sql脚本来生成一个表呀,应该怎么做呀
- 有知道哪有MySQL的汉化/简体中文版下载吗?
- 请问怎么使用MySQL(mysql-4.0.14-win)谢谢了。
- 自己写一个posgres的odbc驱动,那位大侠知道怎么做?分数200!
- 请问: mysql的数据库在windows2000的服务器如何配置?
- 我是新手,请问我安装好mysql后,下一步改怎样操作?怎样建立数据库?以及我的默认超级用户名是什么?
- mysql级联查询自定义函数求指点
- Jive连接MYsql数据库的错误?难道没人知道吗?
- mysql5.0z中插入中文出现乱码??
- 求助:关于mysql编译的问题
你可以用像这样的语句来处理,ISO-8859-1是网上统一的一种编码方式: (Stringname.getBytes("ISO-8859-1"),"GBK")在MYSQL中的乱码:你可以在建表的时候指定字符集,形如这样:
CREATE TABLE tableNAme
(
......
)default character set gbk;我是在XP用的Mysql5。。
我的数据服务器与网站服务器:MYSQL5.0+Tomcat5.0.28+JSP。
1、 把mysql默认字符设置成UTF-82、 在Tomcat加个过滤器 package org.glgk.card.filters;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); }
}Web.xml
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.glgk.card.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>3、 每个JSP页面增加
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
下一步就是你程序的处理了..如果你只是简单的jsp和servlet交互那么你就直接在servlet的post方法中(假定你form提交方式为post),设定request.setCharacterEncoding("UTF-8");即可取得的数据为UTF-8格式,但是插入数据库存储格式为gbk中文.struts中的话将web.xml加入楼上所示的filter.所有前台页面和后台页面都使用UTF-8编码.好的 祝你好运.