• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with foreign characters

 
Saidul Islam
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to handle foreign characters in a request object? In my case, I pass foreign chars from jsps or some presentation layer to some servlet or business logic. To keep the conversation simple say, I want to print these special chars in console or log file or even in the resulting servlet. How do u print that raw data? In my case, it looks like the foreign characters are getting replaced by '?' marks.
Before doing anything to the request object, I call setCharacterEncoding("UTF-8") thought UTF8 is the mother of all and something magical will happen (yea I wish..). It actually gets rid off those foreign chars and any chars after them.
I am doing something like
<pre>
try
{
req.setCharacterEncoding("UTF-8");
}
catch (java.io.UnsupportedEncodingException ue)
{
//do nothing
}
System.out.println(req.getCharacterEncoding());
System.out.println(">" + req.getParameter("firstName") + "<");
</pre>
Here is the input I am trying
<pre>
�������
</pre>
I hope the input value is printed here the way I want.
 
Bhushan Jawle
Ranch Hand
Posts: 249
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
To print non-ascii characters on console, I think you need to have an OS which supports those characters. I had similar problem with Japanese characters, I used to check those by writing them to an HTML file with proper encoding(Shift_JIS in my case).
Hope that helps.
Bhushan
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have an expirience with hebrew. i did the next thing, but this helps only in case of ie:
run this method on the string you have
getBytes("UTF16","Cp1255").substring(2)
the result is visible in internet explorer.
try it, and tell me if it worked and for what language.
 
Saidul Islam
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bhushan Jawle:
Hi,
To print non-ascii characters on console, I think you need to have an OS which supports those characters. I had similar problem with Japanese characters, I used to check those by writing them to an HTML file with proper encoding(Shift_JIS in my case).
Hope that helps.
Bhushan


I guess I am not sure what encoding I should be using. That's the reason I used UTF8 and thought it would include everything.
 
Saidul Islam
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Asher Tarno:
i have an expirience with hebrew. i did the next thing, but this helps only in case of ie:
run this method on the string you have
getBytes("UTF16","Cp1255").substring(2)
the result is visible in internet explorer.
try it, and tell me if it worked and for what language.

hmm... this might work. In my example, I can probly use something like
new String(req.getParameter("nickname").getBytes("UTF-16")).substring(2)
I wonder what the memory utilization going to look like if I use it in a heavy traffic web site.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, it won't be faster for sure!
but at least it will be visible !
 
gautham kasinath
Ranch Hand
Posts: 583
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,
Setting the meta tag to the charset will enable the request to convert the contents to unicode.
Here is a link on how to do it.
Metas
There is another one @ netscape..
Netscape recognised meta tags
I would also advice doing a quick search on google regarding meta tags..
Lupo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic