Solve the problem of Chinese submission under Tomcat! effective!

xiaoxiao2021-03-06  19

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: setcharacterencoding com.jivesoftware.forum.setchangecharsetfilter < PARAM-NAME> Encoding GB2312 setcharacterencoding / *

Yes. I used it when I compiled jive2.6!

转载请注明原文地址:https://www.9cbs.com/read-42482.html

New Post(0)