1, I send a request through firefox: http://localhost:8080/search/q/q/测试
2, Through the Log, I get this:
21:39:16.933 [http-bio-8080-exec-4] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'qqq' processing GET request for [/search/q/q/测试]
21:39:16.933 [http-bio-8080-exec-4] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /q/q/测试
RequestMappingHandlerMapping uses the UrlPathHelper to code the URI. I checked the source code of UrlPathHelper and it use "ISO-8859-1".
Then I used this and it's has no effect in xxx-servlet.xml.Code:<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> <beans:property name="urlPathHelper"> <beans:bean class="org.springframework.web.util.UrlPathHelper"> <beans:property name="urlDecode" value="true" /> <beans:property name="defaultEncoding" value="UTF-8" /> </beans:bean> </beans:property> </beans:bean> <mvc:annotation-driven />
3, controll works well. But I use the 3rd part as an input parameter:
now the parameter "keyword" is 测试. It's coded with "ISO-8859-1" as the "System.out.println" is right. Here I just want to get a "UTF-8" parameter "keyword".Code:@Controller @RequestMapping("/q") public class SearchController { ... @RequestMapping(value = "/q/{keyword}") @ResponseBody public HashMap<String, ArrayList<Game>> searchq(@PathVariable("keyword") String keyword) { try { System.out.println(" -------------------------- " + new String(keyword.getBytes("ISO-8859-1"), "UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } ...
Very apprecaited if anyone who can advise about this or give me a full example. For example, resolve this by xml not hardcoding.


Reply With Quote
