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 Decoding UTF-8 string in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Decoding UTF-8 string in Servlet" Watch "Decoding UTF-8 string in Servlet" New topic
Author

Decoding UTF-8 string in Servlet

r kadam
Greenhorn

Joined: Mar 12, 2003
Posts: 3
I have a simple servlet which persists user entered text into database. The input data is converted to UTF-8 before it is persisted. During retrieval, I am not able to decode the UTF-8 string back to user input text. I am using browser to display the UTF-8 data assuming that browser (<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
) will be able to interpret the UTF-8 value.

Any help how to save and retrieve UTF-8 data will be appreciated. I am using weblogic 8.1, Oracle 9i release 2 and hibernate to persist & retrive the data. The servlet reading the servlet parameter and converts the incoming string to UTF8 using getBytes.

example string: ������
UTF-8 data stored in database: ������������

thanks
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by ksramesh:
I have a simple servlet which persists user entered text into database. The input data is converted to UTF-8 before it is persisted. During retrieval, I am not able to decode the UTF-8 string back to user input text. I am using browser to display the UTF-8 data assuming that browser (<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
) will be able to interpret the UTF-8 value.

Any help how to save and retrieve UTF-8 data will be appreciated. I am using weblogic 8.1, Oracle 9i release 2 and hibernate to persist & retrive the data. The servlet reading the servlet parameter and converts the incoming string to UTF8 using getBytes.

example string: ������
UTF-8 data stored in database: ������������

thanks


I faced this issue earlier.
Use proper content-type attribute in page directive of your JSP page.
I don't remember the syntax, it was something like
<%@ page contentType="text/html; charset=UTF-8" %>

also, do ensure that your data is saved properly in the database.


- Varun
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

"Ksramesh"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decoding UTF-8 string in Servlet