简体   繁体   中英

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. 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. 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. Actual encoding depends on your case.

Sure it is not automatic, but not needed to reconfig servlet context on any servlet server of deployment.

To force JBoss encode url in utf-8 , you can try add to you server configuration:

 <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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