问题
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 %&=
.
回答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.
回答2:
I am getting the same problem. However, I can find the right encoding in the request.getQueryString().
来源:https://stackoverflow.com/questions/9068445/query-string-is-decoded-by-spring-framework