During web development, although the encodingfilter is added to the web. xml file<Filter> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <filter-class> Org. springframework. web. filter. characterencodingfilter </filter-class> <br/> <init-param> <br/> <param-Name> encoding </param-Name> <br/> <param-Value> UTF-8 </param-value> <br/> </init-param> <br/> </filter> <br/> <filter-mapping> <br/> <filter-Name> encodingfilter </filter-Name> <br/> <URL-pattern> *. shtml </url-pattern> <br/> </filter-mapping>
This allows you to use Chinese characters when adding data, but when you update and delete a category, because the categoryid is transmitted through the URL using the get method,
At this time, if categoryid is Chinese, garbled characters will be displayed when passed to the action through URL, and exceptions will occur, interrupting the program.
Solution
Write a tool class
Public class stringdecode {</P> <p> Public static string decode (string value) throws exception <br/>{< br/> try {<br/> If (value = NULL) return NULL; <br/> return new string (value. getbytes ("ISO-8859-1"), "UTF-8"); <br/> // Note: The UTF-8 here depends on the encoding of the submitted page. <br/>}< br/> catch (exception ex) {<br/> return value; <br/>}< br/>
Then, call the decode method in the action.String id = stringdecode. Decode (request. getparameter ("categoryid "));
The obtained ID will not be garbled.
From http://gforge.ce-oss.com/mwiki/index.php/Jsp%E4%B8%AD%E9%80%9A%E8%BF%87get%E6%96%B9%E6%B3%95%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0%E4%B8%BA%E4%B8%AD%E6%96%87%E6%97%B6%E5%87%BA%E7%8E%B0%E4%B9%B1%E7%A0%81%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3%EF%BC%9F"
There is another method:Modify the Tomcat server. the XML file is as follows: <connector uriencoding = "UTF-8" connectiontimeout = "20000" Port = "8080" protocol = "HTTP/1.1" redirectport = "8443"/> This method is relatively simple, I tried it. No problem.