Special character handling in message options for Spring -mvc

I have an application using spring -mvc 3.0. The controllers are configured as follows:

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

When sending an identifier containing special characters (in this case pipe |) url-encoded with UTF-8 (id = 000025D26A01% 7C2014174), the row identifier will contain% 7C. I was expecting spring -mvc to url decrypt the parameter. I know that I can solve this using

 java.net.URLDecoder.decode() 

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

+4
source share
2 answers

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

+1
source

I believe that you are facing the same problem as me. Try using @PathVariable instead of @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 this, you need to change your url and not provide the 'id' parameter. Just "/ update / 000025D26A01% 7C2014174". More information can be found where I found a solution for my problem @RequestParam vs @PathVariable

0
source

All Articles