Because the struts framework sends the form data directly to the Actionform, there is no setcharacterencoding to Httprequestservlet, so the default is to follow Iso-8859-1 (see Tomcat The protected void Parseparameters () method in the Org.apache.catalina.connector.HttpRequestBase in the source code, the solution, is to encode the request before the form is submitted to actionform.
The first method is to write a filter that filters all requests
Filter Code:
package jp.co.ricoh.gtis.others.profile.filters;
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 Setcharacterencodingfilter implements Filter {
Private String encoding;
public void init (Filterconfig filterconfig) throws Servletexception {
//TODO auto-generated method stub
Thi S.encoding=filterconfig.getinitparameter ("encoding");
}
public void Dofilter (ServletRequest request, servletresponse response,
Filterchain chain) throws IOException, Servletexception {
//TODO auto-generated method Stub
Request.setcharacterencoding (This.encodin g);
Chain.dofilter (Request,response);
}
public void Destroy () {
//TODO auto-generated method stub
}
}
Configuration file Web.xml
<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>jp.co.ricoh.gtis.others.profile.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>