4

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

jakobklamra
  • 49
  • 1
  • 1
  • 3

2 Answers2

1

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

frytaz
  • 576
  • 1
  • 4
  • 11
  • Thanks for your answer. However I am already using `org.springframework.web.filter.CharacterEncodingFilter`. All it does is `request.setCharacterEncoding`. My request already has UTF-8, but it cannot transform the special characters as %7C. – jakobklamra Sep 01 '11 at 06:14
  • Maybe you need take a look here http://tech.top21.de/techblog/20100421-solving-problems-with-request-parameter-encoding.html;jsessionid=DAC7E8A568ED4EF9EB181BCDC785B010 – frytaz Sep 01 '11 at 06:50
  • 1
    Thanks a lot. The problem has been solved, and it turns out it was my bad. I've been using Chromes Rest Console to test. This plugin automatically encodes parameters, which means my parameters where double encoded. My bad. It does confirm that my setup was correct. Thanks for all feedback. – jakobklamra Sep 01 '11 at 08:34
0

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

Community
  • 1
  • 1
Augustin Ghauratto
  • 1,420
  • 1
  • 19
  • 21