Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query String is decoded by Spring Framework

Tags:

People also ask

Is RequestParam encoded?

Encoded vs Exact Value Because @PathVariable is extracting values from the URI path, it's not encoded. On the other hand, @RequestParam is encoded.

How does query string work?

The QueryString collection is used to retrieve the variable values in the HTTP query string. The line above generates a variable named txt with the value "this is a query string test". Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.


I'm having a weird problem here, not sure if this is the bug though. The project is running under Spring Framework.

The view:

<form method="GET" action="someUrl.htm" enctype="application/x-www-form-urlencoded" >

    <label>Label</label>
    <input name="val1" value="${val1}" />
  ... 
      <!-- submit button here -->
</form>

Controller mappend to someUrl.htm using SimpleUrlHandlerMapping

<bean id="parameterMethodNameResolver"
        class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">    <property name="methodParamNames">
            ...
</bean>

<bean id="handlerMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">    
        <property name="urlDecode" value="false" />
        <property name="mappings">
            <props>
                <prop key="**/someUrl.htm">someController</prop>
            </props>
        </property>
</bean>

I want to pass % as val1. But when I'm doing this, the following piece of code returns null:

request.getParameter("val1");

catalina.out shows:

WARNING: Parameters: Character decoding failed. Parameter 'val1' with value '%' has been ignored.

I find out that Spring decodes query string and request.getQueryString() returns val1=% but not val1=%25.

How to prevent UrlDecoding here?

Is that a bug? Please notice there is urlDecode parameter is set to false.

Any ideas to workaround the issue, because I really need to use chars like %&=.