• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert to UTF-8.

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic