One, include the page garbled
Phenomenon: Include in the page appears garbled, other pages normal.
Cause: Tomcat uses the ISO-8859-1 encoding by default, but sometimes Tomcat does not correctly parse the included file according to the encoding of the outer. jsp file when included, causing the Chinese garbled in the file include.
Solution: There are many solutions here, but the fundamental solution to our Chinese environment is to modify the core default encoding of Tomcat 5.0.19 from Iso-8859-1 to GBK. You can download the modified jar file at the following address.
Jasper-compiler.jar,jasper-runtime.jar is located under/common/lib, and the other is under/server/lib, replacing the original. jar file with the new.
Second, the submitted data garbled
Phenomenon: The data submitted by the form is garbled.
Reason: The reason is not clear. It is possible that Tomcat, after receiving the request, has not been able to encode the correct encoding according to the information in request.
Workaround: You can add a filter that sets the character set.
Package 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;
Import javax.servlet.UnavailableException;
public class Setcharacterencodingfilter implements Filter {
protected String encoding = NULL;
protected Filterconfig filterconfig = null;
Protected Boolean ignore = true;
public void Destroy () {
this.encoding = null;
This.filterconfig = null;
}
public void Dofilter (ServletRequest request, servletresponse response,
Filterchain chain)
throws Ioexc Eption, Servletexception {
//conditionally Select and set character encoding to is used
if (Ignore | | (request.getcharacterencoding () = null)) {
String encoding = selectencoding (request);
if (encoding!= null)
Request.setcharacterencoding (encoding);
}
//pass control on to the next filter
Chain.dofilter (request, response);
}
public void init (Filterconfig filterconfig) throws Servletexception {
This.filterconfig = filterconfig;
this.encoding = Filterconfig.getinitparameter ("encoding");
String value = filterconfig.getinitparameter ("Ignore");
if (value = = null)
This.ignore = true;
else if (Value.equalsignorecase ("true"))
This.ignore = true;
else if (value.equalsignorecase ("yes"))
This.ignore = true;
else
This.ignore = false;
}
Protected String selectencoding (ServletRequest request) {
return (this.encoding);
}
}
Configure Web.xml
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>