简体   繁体   English

JBOSS + SPRING RequestParam URL编码

[英]JBOSS+SPRING RequestParam URL ENCODING

I have an endpoint 我有一个端点

@RequestMapping(value="/register")
public String register(@RequestParam("p") String p) {

}

The value passed to p parameter is actually an encoded URL. 传递给p参数的值实际上是一个编码的URL。 However, when it reaches my endpoint, it's automatically converted to the decoded form. 但是,当到达我的端点时,它会自动转换为解码形式。 I want it to stay in the encoded form. 我希望它保持编码形式。

Is there a way to do it? 有办法吗? Perhaps some configuration? 也许一些配置?

I agree with @JB Nizet. 我同意@JB Nizet。 Most convenient way is: 最方便的方法是:

@RequestMapping(value="/register")
public String register(@RequestParam("p") String p) {
    p = URLEncoder.encode(value, "utf-8");
}

where utf-8 is just for example. utf-8为例。 Actual encoding depends on your case. 实际编码取决于您的情况。

Sure it is not automatic, but not needed to reconfig servlet context on any servlet server of deployment. 确保它不是自动的,但不需要在任何部署的servlet服务器上重新配置servlet上下文。

To force JBoss encode url in utf-8 , you can try add to you server configuration: 要在utf-8强制JBoss编码url,可以尝试将其添加到服务器配置中:

 <system-properties>
        <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
        <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
 </system-properties>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM