This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Problem converting form data to UTF-8 on solaris Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem converting form data to UTF-8 on solaris" Watch "Problem converting form data to UTF-8 on solaris" New topic

Problem converting form data to UTF-8 on solaris

r kadam

Joined: Mar 12, 2003
Posts: 3
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);
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 231

Try this:

SCJP2, SCWCD 1.4, PMP, ITIL Foundation
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Problem converting form data to UTF-8 on solaris
It's not a secret anymore!