mysql_config 乱码_MYsql 字符集乱码的问题,困扰了好久,帮我解决了再加100分

展开全部

1、MySQL库、表存储设置UTF-8

2、驱动连接字符串String url=

”jdbc:mysql://127.0.0.1:3306/dbname?useUnicode=true&characterEncoding=UTF-8“

3、JSP页面中

这样应32313133353236313431303231363533e58685e5aeb931333332616532该就可以传递正确编码了、不过你的输入输出环节的转换代码具体是什么样的?

此前如果有遗漏可能还要检查:

4、设置Tomcat6的server.xml中标签:

URIEncoding="utf-8" useBodyEncodingForURI="true" redirectPort="8443" />

5、JSP页面读取后台中文变量

控制装饰层从前端接收中文变量String aStrVal =new String(req.getParameter("strPara").getBytes("ISO8859_1"));

6、如果第4个措施因特殊情况不能修改,则可以自己写过滤器:package 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;

import javax.servlet.UnavailableException;

public class SetCharacterEncodingFilter implements Filter {

/**

* The default character encoding to set for requests that pass through

* this filter.

*/

protected String encoding = "UTF-8";

/**

* The filter configuration object we are associated with.  If this value

* is null, this filter instance is not currently configured.

*/

protected FilterConfig filterConfig = null;

/**

* Should a character encoding specified by the client be ignored?

*/

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 {

// Conditionally select and set the character encoding to be used

if (ignore || (request.getCharacterEncoding() == null)) {

String encoding = selectEncoding(request);

if (encoding != null)

request.setCharacterEncoding(encoding);

}

chain.doFilter(request, response);

}

/**

* Place this filter into service.

* @param filterConfig The filter configuration object

*/

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);

}

}

encodingFilter

filters.SetCharacterEncodingFilter

encoding

GBK

ignore

false

encodingFilter

/*

另外请确认如下都已经设置好:

MySQL 5.1在在my.ini内的 [mysql] 和[mysqld]两处 default-character-set=utf8

MySQL 5.5在在my.ini内的 [mysql]default-character-set=utf8;[mysqld]character-set-server=utf8

Myeclipse偏好首选设置里:

General->Workspace    Text file encoding;

General->Content Types,右侧Content Types树,点开Text,确认Java Source File下面的Default encoding框中是UTF-8,用到jsp、js、css同上;

--看你的截图只是数据前后交换的问题,项目工作空间的都没问题了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值