Win a copy of Terraform in Action this week in the Cloud forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem converting form data to UTF-8 on solaris

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to convert input parameter to UTF8 and then again get the original string from UTF8. This servlet works fine in Windows2000 but on solaris the converted value is not UTF8 but the original input parameter value. Is the code below the right way to convert the input string to UTF8 and to retrieve the original string back from UTF8.

Thanks in advance.

Convert input String to UTF-8:

// set the character encoding to UTF-8

// retrieve the bytes for firstName parameter
byte[] pb1 = req.getParameter("firstName").getBytes("UTF8");

// store the UTF8 String
String pb1Str = new String(pb1);

System.out.println("UTF8 String:" + pb1Str);

Retrieve input String from UTF-8:

// get the bytes from UTF-8 String
byte[] pb2 = pb1Str.getBytes();

// Decode the String from UTF-8
String pb2Str = new String(pb2, "UTF8");

System.out.println("Original String:" + pb2Str);
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic