关于structs中的汉字如何处理????????急啊??在线等待
我配置的数据库连接:
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">
MySQL_JDBC
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://127.0.0.1:3306/proc?useUnicode=true&characterEncoding=gb2312
</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">mysql</property>
</session-factory>
</hibernate-configuration>
我写的文字过滤器:
package com.tarena.servlets;
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 EncodingFilter 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;
}
}
我的文字过滤器的配置:
<filter>
<filter-name>encodfilter</filter-name>
<filter-class>com.tarena.servlets.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
问题:1,如果我给数据库中插入带有汉字的数据时,不让录入怎么解决???
2,在structs中action中得到数据,利用EL表达式在JSP中显示,不能显示汉字,在action中也是乱码,怎能解决???
拜托个位了,急急!!!!
------解决方案--------------------中插入带有汉字的数据时,不让录入怎么解决???
不让录入是啥意思?你的异常是啥?贴上来
1 你的数据库创建时,使用的编码集错了,应该用GBK
2 你的字段不够长
------解决方案--------------------<filter>
<filter-name>encodfilter </filter-name>
<filter-class>com.tarena.servlets.EncodingFilter </filter-class>
<init-param>
<param-name>encoding </param-name>
<param-value>GB2312 </param-value>
</init-param>
<init-param>
<param-name>ignore </param-name>
<param-value>true </param-value>