中文乱码问题---前台输入的内容为什么在数据库中查看全是乱码呀 - Web 开发 / 其他
我已经做过过滤了,为什么还是乱码呀???求大神。。。。
web.xml
<!--中文编码过滤器-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.shjob.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gbk</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
CharacterEncodingFilter.java
/** 编码过滤器 */
public class CharacterEncodingFilter implements Filter {
String encoding = null;
FilterConfig filterConfig = null;
/** 初始化方法 */
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
/** 过滤处理方法 */
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (encoding!=null){
//对请求进行编码设置
request.setCharacterEncoding(encoding);
}
//将处理权转交给下一个处理器
chain.doFilter(request,response);
}
/** 销毁方法 */
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
}
jsp页面开头
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
mysql数据库用的也是gbk!
为什么还是乱码呢。。。各位大神,急用呀。。。。谢谢啦
[解决办法]