由於Struts框架直接把表單數據發送給了ActionForm
解決的方法
第一種方法
過濾器代碼
package
import java
import javax
import javax
import javax
import javax
import javax
import javax
public class SetCharacterEncodingFilter implements Filter {
private String encoding;
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto
this
}
public void doFilter(ServletRequest request
FilterChain chain) throws IOException
// TODO Auto
request
chain
}
public void destroy() {
// TODO Auto
}
}
配置文件web
<filter>
<filter
<filter
<init
<param
<param
</init
</filter>
<filter
<filter
<url
</filter
第二種方法是替換默認的控制器org
子類代碼
package
import java
import javax
import javax
import javax
import org
public class SetEncodingActionServlet extends ActionServlet {
protected void process(HttpServletRequest request
// TODO Auto
String encoding = getInitParameter(
request
super
}
}
配置文件web
<servlet>
<servlet
<servlet
<init
<param
<param
</init
<init
<param
<param
</init
<load
</servlet>
<servlet
<servlet
<url
</servlet
此例
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28167.html