写一个MyActionServlet来并覆盖ActionServlet中的process()方法。
添加一行代码:request.setCharacterEncoding("gbk");就可以了.
package com.ke.struts;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionServlet;
public class MyActionSerlvet extends ActionServlet
{
@Override
protected void process(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
request.setCharacterEncoding("gbk");
super.process(request, response);
}
}
当然别忘了改一下web.xml里面的配置
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.ke.struts.MyActionSerlvet</servlet-class><!-- 需要修改的地方 -->
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
改一下servlet-class标签中的内容就可以!
真的可以,一劳用yi!
具体编码的理论就不说了,google上已经够多了。
另外,如果不用struts的话,hibernate也可能碰到中文乱码问题,
只要在hibernate.cfg.xml配置中如下:
<property name="hibernate.connection.url"> jdbc:microsoft:sqlserver://Localhost:1433;SelectMethod=cursor;characterEncoding=GBK;DatabasName=myDatabase.
</property>
characterEncoding=GBK!就可以了
posted on 2007-08-17 14:09
Ke 阅读(655)
评论(0) 编辑 收藏 所属分类:
struts