wood burning stoves
The moose likes JSP and the fly likes Convert to UTF-8. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Convert to UTF-8." Watch "Convert to UTF-8." New topic
Author

Convert to UTF-8.

Viet Jav
Ranch Hand

Joined: Dec 27, 2001
Posts: 55
Hi frineds,
I have code fragment(JSP) as below, my aim is convert Unicode characters into UTF-8. Parameter "save" contains Unicode characters(Vietnamese characters) got from editor box on browser. These characters stored in String variable called save. Output of variable save(SAVE 1) is not correct that mean is not Vietnamese characters. So I convert them into UTF-8 in try/catch block. As a result of output(SAVE 2), they show Vietnamese characters correctly but my data outputed is missed many characters.
What are anything wrong? Please have a hints.
Thanks in advandce.
String save = request.getParameter("save");
System.out.println("SAVE 1 = "+save);
if (save != null) {
try {
save = new String(save.getBytes(),"UTF-8");
System.out.println("SAVE 2 = "+save);
} catch (UnsupportedEncodingException e) {
}
Vietjav.
Viet Jav
Ranch Hand

Joined: Dec 27, 2001
Posts: 55
Hi,
I'm sure that I using JSP that not support method:
void setCharacterEncoding(java.lang.String enc)
throws java.io.UnsupportedEncodingException
in Request object.
Have anyway to solve my trouble?
Vietjav.
Viet Jav
Ranch Hand

Joined: Dec 27, 2001
Posts: 55
Hi,
I tried and it is work now, the following is my code:
try {
byte[] utf8 = str.getBytes(request.getCharacterEncoding());
str = new String(utf8, enc);
} catch (UnsupportedEncodingException e) {
//System.out.println("UTF8-ERROR = "+e.toString());
}
 
Have you checked out Aspose?
 
subject: Convert to UTF-8.
 
It's not a secret anymore!