• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encoding (internationalization) of parameters in HttpServletRequest

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a web application, where the user fills in a < form > and sends it to a servlet.
The servlet reads the form using HttpServletRequest.getParameter(..).

The problem is: user may fill the form with strings in a foreign language (Chinese/Japanese, in my case).

Unfortunately, when I call request.getParameter() , I get gargage instead of my Chinese data.
That happens even when though I made sure that the original form is sent to the browser with the appropriate content type ("text/html ; charset=...")

Thus, my question is: is there a way to tell the browser which encoding to use when it sends me the form data ?
In general, is there a portable way to work with internationalized form parameters (it shoud be protable between different types of browsers, as well as different vendors of j2ee containers).

Thank you very much.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my understanding, a browser fills parameters using the current page encoding (unless an end user override that from menu). Since I do servlet app which should work in many languages (specifically in Russian) I use UTF-8 and never had a problem to get correct values. I'd recommend to call req.setCharacterEncoding(your_page_encoding) before accessing parameters.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you by any chance using GET to submit your form? Then this page explains what you need to do to solve the problem. The gist of it is: GET parameters are not decoded by Tomcat the way you might expect it to happen. (The article talks about TC 5.5, but it also works in TC 5.0)
[ March 06, 2006: Message edited by: Ulf Dittmer ]
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for all those excellent replies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!