Method One: It only works for a single string
String name=request.getparameter ("name");
Name=new String (name.getbytes ("iso-8859-1"), "Utf-8");
method Two: Valid for the current page
Request.setcharacterencoding ("GBK");
String name=request.getparameter ("name");
method Three: Valid for the entire Web site
Using filter principle
public class setencodingfilter implements filter { protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; public void destroy () { this.encoding = null; this.filterConfig = null;    &NBSP} public void dofilter (ServletRequest request, servletresponse response, Filterchain chain) throws ioexception, servletexception { if (ignore | | (request.getcharacterencoding () == null)) { &nbsP; request.setcharacterencoding (selectEncoding (request)); } Chain.dofilter (Request, response);    &NBSP} 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") | | value.equalsignorecase ("yes") this.ignore = true; else this.ignore = false;    &NBSP} protected string selectencoding (ServletRequest request) { return (this.encoding)  &NBSP} public filterconfig getfilterconfig () { return filterConfig;    &NBSP} public void setfilterconfig (FilterConfig Filterconfig) { this.filterconfig = filterconFig    &NBSP}}
Web.xml
<filter> <filter-name>SetCharsetEncodingFilter</filter-name> <filter-class>filter. Setencodingfilter</filter-class> <init-param> <param-name>encoding</param-name > <param-value>gbk</ Param-value> </init-param> < /filter> <filter-mapping> < Filter-name>setcharsetencodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>