开发者

Handling special characters in post parameters for Spring-mvc

I have an application using spring-mvc 3.0. The controllers are configured like this:

@RequestMapping(value = "/update", method = RequestMethod.POST)
public ModelAndView updateValues(
 @RequestParam("einvoiceId") String id){
...}

When posting an id that contains special characters (in this case pipe |), url-encoded with UTF-8 (id=000025D26A01%7C2014174) the string id will contain %7C. I was expecting spring-mvc to url decode the parameter. I am aware that I can solve this by using

java.net.URLDecoder.decode()

but since I have a large number of controllers, I would like this to be done automatically by the framework. I have configured 开发者_Python百科the Tomcat connector with URIEncoding="UTF-8" and configured a CharacterEncodingFilter, but as I understand it this will only affect GET requests. Any ideas on how I can make spring-mvc url decode my post parameters?


http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q3 This page says CharacterEncodingFilter can change POST parameters


I believe you encounter the same issue as I did. Try using @PathVariable instead @RequestParam.

@PathVariable is to obtain some placeholder from the uri (Spring call it an URI Template) — see Spring Reference Chapter 16.3.2.2 URI Template Patterns

If you do, you have to change your url and don't provide parameter 'id'. Just "/update/000025D26A01%7C2014174". More information can be found where I found the solution for my problem @RequestParam vs @PathVariable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜