展开全部
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同上;
--看你的截图只是数据前后交换的问题,项目工作空间的都没问题了。