• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Encoding (internationalization) of parameters in HttpServletRequest

 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for all those excellent replies
 
reply
    Bookmark Topic Watch Topic
  • New Topic