新建一个SetCharacterEncodingServlet的类(继承ActionServlet),重写process()方法。如下示:
protected void process(HttpServletRequest request,
HttpServletResponse response) throws java.io.IOException,
javax.servlet.ServletException
{
request.setCharacterEncoding("UTF-8");
super.process(request, response);
}
在web.xml中部署ActionServlet。
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com..util.UTF8ActionServlet</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>