First write a class: Import java.io.ioException; import javax.servlet. *;
Public class setchangecharsetfilter imports filter {
Protected string encoding = null; / To formulate the encoding, configure it in web.xml
Protected filterconfig filter firmconfig = NULL;
Public void destroy () {
THIS.Encoding = null; this.filterconfig = NULL;
}
Public void Dofilter (ServletRequest Request, ServletResponse Response, Filterchain Chain) throws ioException, servletexception {
IF (Request.getCharacterencoding () == null) {string encoding = getencoding (); get the specified encoded name if (Encoding! = null) Request.setCharacterencoding (Encoding); Setup Code}
Chain.dofilter (Request, Response); // Have the opportunity to execute the next Filter
}
Public void init (filterconfig filterconfig) throws servletexception {
This.filterconfig = filterconfig; this.encoding = filterconfig.getinitParameter ("eNCoding"); // get encoding in Web.xml}
protected string getencoding () {
Return (this.encoding); // get the specified encoding
}
}
Then write a paragraph in the web.xml document:
Yes. I used it when I compiled jive2.6!