Document directory
- 1. filter class:
- 2. Web. xml file:
Solution:
Set a filter in the background to filter and convert the encoding!
The procedure is as follows:
1. filter class:
Public class loggerfilter implements filter {
Private string encoding = "GBK ";
Private filterconfig fiterconfig = NULL;
Public void destroy (){
}
Public void dofilter (servletrequest request, servletresponse response,
Filterchain) throws ioexception, servletexception {
This. Encoding = fiterconfig. getinitparameter ("encoding ");
If (this. Encoding = NULL ){
Encoding = "GBK ";
}
Request. setcharacterencoding (this. Encoding );
Response. setcharacterencoding (this. Encoding );
Filterchain. dofilter (request, response );
}
Public void Init (filterconfig) throws servletexception {
}
2. Web. xml file:
<Filter>
<Filter-Name> loggerfilter </filter-Name>
<Filter-class> cn.com. sinosoft. Filter. loggerfilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> loggerfilter </filter-Name>
<URL-pattern> *. DO </url-pattern>
</Filter-mapping>