Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Tomcat : can you configure encoding for HttpServletRequest getParameter()  RSS feed

Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Report post to moderator

I'm using tomcat 5.5.15.

I have a servelt which reads parameters from a < form > , using HttpServletRequest.getParameter().
The catch is, parameters data (filled in by the user) is in Chinese.

I noticed that even though my page encoding is "unicode", the browser (IE6) seems to send the parameters in utf-8 (I'm not sure whether it's part of the HTTP spec, or is it and IE6 thing.... ?).

Unfortunately, Tomcat's implementation for HttpServletRequest.getParameter() returns garbage, because it does *not* assume that parameters are encoded in utf-8 (it seems to assume "latin1", or something very similar).
I did manage to forcefully convert the data, using the following ugly code:

I was wondering, is there a nicer way to do it ?
E.g. is there some tomcat configuration file, where you can tell it the request.getParameter() should parse the data assuming the browser sent it using utf-8 ?

Thanks very much.
Posts: 67260
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
how do I do my own kindle-like thing - without amazon
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!