File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes problem with foreign characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with foreign characters" Watch "problem with foreign characters" New topic
Author

problem with foreign characters

Saidul Islam
Greenhorn

Joined: Dec 05, 2000
Posts: 18
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.


<b>JStar</b><BR>
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
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

Joined: Jul 28, 2001
Posts: 260
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.


Asher Tarnopolski
SCJP,SCWCD
Saidul Islam
Greenhorn

Joined: Dec 05, 2000
Posts: 18
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

Joined: Dec 05, 2000
Posts: 18
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

Joined: Jul 28, 2001
Posts: 260
well, it won't be faster for sure!
but at least it will be visible !
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
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


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with foreign characters
 
Similar Threads
character convertion in java
What is the encoding I should to get the polish characters correctly from request?
baffling UTF-8 problem
Character Encoding issue with Tomcat 5.5.9
javacc - communicating from lexer to parser