Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC: @ModelAttribute decoded correctly but @RequestParam decoded wrongly Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC: @ModelAttribute decoded correctly but @RequestParam decoded wrongly

    For @ModelAttribute scenario, the request is generated by browser.
    Here is the request information
    Code:
    Request URL:http://localhost:8080/Azelea/register
    Request Headersview source
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Content-Type:application/x-www-form-urlencoded
    Origin:http://localhost:8080
    Referer:http://localhost:8080/Azelea/register
    User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
    Form Dataview URL encoded
    email:[email protected]
    password:11
    salutation:先生
    fullName:组件
    company.name:
    company.id:
    locale:zh_CN
    thanks for filter org.springframework.web.filter.CharacterEncodingFi lter in web.xml, the chinese character in salutation and fullName are read correctly by ModelAttribute in controller.

    For @RequestParam scenario, the request is generated by jQuery UI autocomplete.
    Here is the request information
    Code:
    Request URL:http://localhost:8080/Azelea/company/search?term=%E4%BA%A4%E4%BA%92
    Request Headersview source
    Accept:application/json, text/javascript, */*; q=0.01
    Referer:http://localhost:8080/Azelea/register
    User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
    X-Requested-With:XMLHttpRequest
    Query String Parametersview URL encoded
    term:交互
    Notice the term is correctly encoded as %E4%BA%A4%E4%BA%92
    but in this case, the controller get a wrong term: δΊ€δΊ’
    the signature of this controller is:
    Code:
    @RequestMapping(value = "/company/search", method = RequestMethod.GET)
    @ResponseBody 
    public List<Organization> findCompanyName(@RequestParam(required=false) String term) {
    where is the problem? why CharacterEncodingFilter can't work on second scenario?
    Last edited by truetime; Sep 18th, 2012, 07:50 AM.

  • #2
    Hi Try,
    @RequestMapping(value = "/company/search", method = RequestMethod.GET, headers = "Accept=*/*")
    public @ResponseBody
    List<Organization> getNameList(@RequestParam("term") String term) {

    Comment


    • #3
      I tried, but didn't work.

      Comment

      Working...
      X