• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decoding UTF-8 string in Servlet

 
r kadam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic