-1

Queryparameter URL : AspectValues?aspectName=US+Shoe+Size+(Women%27s)

When I using :

@RequestMapping(value = "AspectValues", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getAspectValues(@RequestParam String aspectName)

aspectName is getting populated as "US Shoe Size (Women s)" instead of "US Shoe Size (Women's)"

It would be helpful if any of you could let me know when percent encoding happens, would it give any value as space and the reason for such behavior.

A0__oN
  • 8,740
  • 6
  • 40
  • 61
Rishi
  • 1,163
  • 7
  • 12

2 Answers2

0

add charecter encoding filter

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

or bean

@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    registrationBean.setFilter(characterEncodingFilter);
    return registrationBean;
}
kuhajeyan
  • 10,727
  • 10
  • 46
  • 71
  • I have already added this in web.xml, but it doesn't work. I have tested this using postman, it doesn't work for just %27, when we change %27 to % 28 or any other know utf-8 values, it works perfectly fine. Do you have any idea over this? – Rishi Aug 24 '16 at 00:47
  • What makes you think that `CharacterEncodingFilter` affects anything but the body of the request or response? – Sotirios Delimanolis Aug 24 '16 at 01:23
  • @Sotirios then what do you think the issue is ? – Rishi Aug 24 '16 at 21:05
  • @Rishi I don't know. I can't reproduce this. You might want to add a [MCVE] to your question. – Sotirios Delimanolis Aug 24 '16 at 21:58
  • @Sotirios I would add one, but before that just use any url such as http://localhost:8080/rpt/getCatValues?aName=Size+(Women%27s), which has single quote to see if the parameter being passed is "Size Women's" or "Size Women s". This would help you in reproducing the error and would add an concrete example in sometime. – Rishi Aug 24 '16 at 22:08
  • @Rishi That's what I meant by _I can't reproduce this._ – Sotirios Delimanolis Aug 24 '16 at 22:28
-1

The question is not specific to Spring . Rather it is more into how Java handles the uri. You can take a look into java.net.uri to handle the issue.

The question has well been answered into this post

Community
  • 1
  • 1
Sohil
  • 532
  • 7
  • 26