9

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 %&=.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Sqeezer
  • 1,267
  • 2
  • 14
  • 23
  • Which Spring version are you using? – ustun Jan 30 '12 at 18:32
  • Can you not encode the characters? http://www.ietf.org/rfc/rfc2396.txt defines % as starting en escaped sequence, not obeying this will probably cause you problems. – Roger Lindsjö Jan 30 '12 at 18:47
  • 2
    rfc2396 states that '%' must be escaped as '%25'. 'application/x-www-form-urlencoded' does that for free. The problem here is that Spring decodes query string and then, when I'm trying to call getParameter the query parameter is decoded second time. So, to prevent that we should somehow tell Spring not to decode query string. – Sqeezer Jan 30 '12 at 19:06
  • Why are you doing a GET from a form instead of a POST? – GriffeyDog Jan 30 '12 at 21:16
  • %, ?, and & are bad characters to use in a url and need to be escaped. – bmoran Jan 31 '12 at 03:53
  • It doesn't matter if I use GET or POST. I see that browser sends var1=%25&var2=etc. But on Controller side the query string looks like var1=%&var2=etc. JavaDoc says that getQueryString returns not decoded string. Then decoding happen in Spring itself. I thought 'urlDecode' is responsible whether to decode or not, but it does not affect at all. I do not use %?& in URL, I just want to pass them, 'application/x-www-form-urlencoded' is handling URL encoding there. – Sqeezer Jan 31 '12 at 06:53
  • 1
    If you reckon it's a bug, then at the very least upgrade to the latest version of Spring 2.0.x (i.e. 2.0.8). But you really should upgrade to something newer, 2.0 is very old indeed. – skaffman Jan 31 '12 at 11:12

2 Answers2

1

What you have to do is not use Spring's parameter map. Create a filter that will read the query string in its raw format, decode it yourself, get the values you need and add them to a bean that can be read later when you need it. I'm vague about how to do the latter part because Spring 2.0.5 is old and anything I tell you may not work in that version. An object that is in session scope should be fine.

0

I am getting the same problem. However, I can find the right encoding in the request.getQueryString().

Ojitha
  • 950
  • 7
  • 8