Query string decoded by Spring Framework

I have a strange problem here, but I'm not sure if this is a mistake. The project works under the Spring Framework.

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> 

The controller switches 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 do this, the following code fragment returns null:

 request.getParameter("val1"); 

catalina.out shows:

WARNING: Parameters: character decoding failed. The parameter "val1" with the value "%" was ignored.

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

How to prevent urldecoding here?

This is mistake? Note that urlDecode set to false .

Any ideas to solve this problem, because I really need to use characters like %&= .

+8
java spring-mvc forms servlets urldecode
source share
2 answers

What you need to do is not to use the Spring parameter map. Create a filter that will read the query string in raw format, decode it yourself, get the necessary values ​​and add them to the bean, which can be read later when you need it. I don’t understand how to do the last part, because Spring 2.0.5 is old and everything that I tell you may not work in this version. An object that is in the session area must be accurate.

+1
source share

I have the same problem. However, I can find the correct encoding in request.getQueryString ().

0
source share

All Articles