---- * Web. xml *----
<Filter>
<Filter-Name> myfilter </filter-Name>
<Filter-class> cray. util. myfilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> myfilter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
------------ Myfilter. Java -------------
Import javax. servlet .*;
Import javax. servlet. http. httpservlet;
Import java. Io. ioexception;
Public class myfilter extends httpservlet implements Filter
{
Private filterconfig;
Public void Init (filterconfig) throws servletexception
{
This. filterconfig = filterconfig;
}
Public void dofilter (servletrequest request, servletresponse response,
Filterchain)
{
Try
{
Request. setcharacterencoding ("GBK ");
Filterchain. dofilter (request, response );
} Catch (servletexception SX)
{
Filterconfig. getservletcontext (). Log (sx. getmessage ());
} Catch (ioexception iox)
{
Filterconfig. getservletcontext (). Log (iox. getmessage ());
}
}
Public void destroy ()
{
}
}