Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Internationalization  RSS feed

 
boon boh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi....
Can anyone please help the following:
- When a servlet handles request from client platform of multiple different language and locale, what is the encoding of the returned string when we do a (String)request.getParameter("XX")?
 
Gyula Klinszky
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am not sure if I interpreted your question correctly
Anyway, to determine the encoding of a request just call the getCharacterEncoding() method of ServletRequest. The returned value should be a a valid character encoding.
 
boon boh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering the various possible client platform's regional setting and the various languages input mechanism for http "form" data, is there a standard encoding used for the submitted data such that the webserver do not have to worry about the handling the client's data encoding differences?
 
k doshi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the following
request.setCharacterEncoding("UTF-8")
 
boon boh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we know the the data coming from client is "UTF-8" encoded? is it a default encoding for all http request?
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thuogh due to version problem of servlet.jar i never used, method setCharacterEncoding ... but here is how I went:
In every JSP page, I used UTF-8 encoding
<%@ page language="java"
contentType="text/html;charset=UTF-8">
[or alternatively you can achieve this by, using response.setContentType("text/html;charset=UTF-8") in servlets] and when u will submit any request from these pages(UTF encoded), though your servlet *will receive the request in UTF-8, but still params in request undergoes some change as each of them tend to get "0" i.e. leading zero's appended ... !!!
Hence before any operation, use
new String(request.getParameter(String).getBytes(strEncodingSrc));
where strEncodingSrc = encoding of box where application is running ... for windows
"ISO8859-1" .
Hope this helps !!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!