查询字符串由Spring Framework解码 [英] Query String is decoded by Spring Framework

查看:167
本文介绍了查询字符串由Spring Framework解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个奇怪的问题,不知道这是否是错误。
该项目在Spring Framework下运行。

观点:$ b​​
$ b

 < form method =GET action =someUrl.htmenctype =application / x-www-form-urlencoded> 

< label>标签< / label>
< input name =val1value =$ {val1}/>
...
<! - 在此处提交按钮 - >
< / form>

控制器映射到 someUrl.htm 使用 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 =urlDecodevalue =false/>
< property name =mappings>
<道具>
< prop key =** / someUrl.htm> someController< / prop>
< /道具>
< / property>
< / bean>

我想将作为 VAL1 。但是当我这样做时,以下代码将返回空值:

  request.getParameter(val1); 

catalina.out显示:


警告:参数:字符解码失败。

我发现Spring解码查询字符串和 request.getQueryString()返回 val1 =%但不是 val1 =%25



如何防止UrlDecoding在这里?



这是一个错误吗?请注意, urlDecode 参数设置为 false



<任何想法来解决这个问题,因为我真的需要使用字符如%& =

解决方案

你必须做的不是使用Spring的参数映射。创建一个过滤器,它将以原始格式读取查询字符串,自己解码,获取所需的值,并将它们添加到稍后可以在需要时读取的bean中。我对如何完成后一部分很模糊,因为Spring 2.0.5是旧的,我告诉你的任何东西都可能不适用于该版本。一个处于会话范围内的对象应该没问题。


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

解决方案

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.

这篇关于查询字符串由Spring Framework解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆