views:

26

answers:

2

My project requires me to write a web application with JSP to communicate with Oracle 10g R2

The JSP/Javascript/HTML is held in OC4J 9i and the database is created with characterset as UTF-8. The interface between JSP and Oracle is based on JDBC Thin driver

I tried to type in some Chinese characters on JSP page, then save to Oracle. In Oracle (SQL Plus), those characters cannot be shown correctly. Then the characters cannot be shown correctly too with ResetSet.getString.

FYI, the page directive for each JSP is already <%@ page contentType='text/html; charset=utf-8' pageEncoding='utf-8'%>

Any hint ?

A: 

I tried to type in some Chinese characters on JSP page

  • The page encoding of that JSP page must be set to UTF-8.

    <%@ page pageEncoding="UTF-8" %>
    

    Verify with a HTTP response header checker tool like Firebug if the response has been arrived with the Content-Type: text/html; charset=UTF-8 header.

  • The servlet which is postprocessing the submitted data in doPost() must set request encoding to UTF-8 before accessing the parameters.

    request.setCharacterEncoding("UTF-8");
    

    If it's actually a GET request and you're gathering parameters in doGet(), then you instead need to configure the servletcontainer in question to use UTF-8 to decode the query string. Here's a Tomcat-targeted example:

    <Connector (...) URIEncoding="UTF-8" />
    

then save to Oracle. In Oracle (SQL Plus), those characters cannot be shown correctly.

  • The database must be created with the correct character set:

    CREATE DATABASE dbname CHARACTER SET UTF8
    

Then the characters cannot be shown correctly too with ResetSet.getString.

  • If you've taken all the aforementioned steps, this problem should be fixed now.

See alsoe:

BalusC
A: 

Make sure defaultNChar is set to true on the JDBC connection. See defaultNChar property.

Janek Bogucki