Reputation: 31
I am fetching a Japanese string from Oracle Database and displaying it on the browser. But the characters are shown on the browser like ???. Inserted the Japanese string into DB using the unistr() function.
INSERT INTO MESSAGES (MESSAGE_ID,MESSAGE) VALUES (1,unistr('\0041\0063\0063\0065\0073\0073\0020\004d\0061\006e\0061\0067\0065\006d\0065\006e'));
I got this in my jvm logs ISO8859-1
when I printed System.getProperty("file.encoding")
.
select * from v$nls_parameters where parameter in ('NLS_CHARACTERSET')
yields UTF8
in my DB.
Any pointers on how the Japanese characters could be displayed correctly ?
Upvotes: 3
Views: 6157
Reputation: 192
you are try to change the ISO8859-1 into utf-8.
if above issue in struts use this code on your java.jsp page
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
Upvotes: 2
Reputation: 2184
\0041\0063\0063\0065\0073\0073\0020\004d\0061\006e\0061\0067\0065\006d\0065\006e
doesn't seem to be a valid Japanese UTF-8 string (It means "Access Managemen"
in UTF-8).
If you want to insert Japanese characters into CHAR
column, try unistr('\306b\307b\3093\3054')
(It means "にほんご"
in UTF-8).resultSet.getString(2);
with debugger, you will see the inserted Japanese string.<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
at the head of JSP file.
The default encoding of JSP is ISO-8859-1 (see https://docs.oracle.com/cd/E17802_01/j2ee/j2ee/1.4/docs/tutorial-update6/doc/WebI18N5.html ), and it cannot handle Japanese characters.Upvotes: 0
Reputation: 1108722
If you are seeing ???
in the webbrowser, then changing the browser's locale/charset as suggested by others really won't help much. Only if you were seeing �
, empty squares and/or Mojibake, then it may indeed help. Also installing fonts really won't help much as well. If there wasn't a font for it, you would in Firefox have seen squares with hexcodes inside and in IE empty squares and really not ???
.
The ???
can here have only one cause: you are writing those characters to the HTTP response using the wrong encoding. The average webserver will replace unknown characters by ?
. The webbrowser doesn't do that, it is just displaying them as is. Actually, there is in theory another possible cause; the DB will do the same when you're inserting unknown characters, but that's less or more excluded here.
It's not clear what view technology you're using, but since you're talking about Java and a webbrowser, I'll assume that you're using JSP/Servlet (in the future, please mention and tag as such, so that the right audience will be reached).
If you're displaying those characters using JSP, then you need to add the following to the top of your JSP page to instruct the servletcontainer to write those characters using the right encoding:
<%@ page pageEncoding="UTF-8" %>
If you're writing those characters manually using a Servlet, then you need to set the HTTP servlet response to use the right encoding as follows before you write any character to it:
response.setCharacterEncoding("UTF-8");
Upvotes: 0
Reputation: 4588
Checklist:
select unistr('\0041\0063\0063\0065\0073\0073\0020\004d\0061\006e\0061\0067\0065\006d\0065\006e') from dual
If #3 is successful, then the file encoding of the message field in your table is incorrect.
Upvotes: 1
Reputation: 76709
The character of the server's response to the browser appears to be incorrectly specified as far as Unicode encoding is concerned. There is a fairly detailed SO question on this topic, if you're using Tomcat. Do note that you have to use UTF-8 and not ISO-Latin-1/ISO-8859-1 as Japanese characters do not fall into the Latin-1 character encoding.
In addition to the pointers about Unicode encoding, you might want to check a couple of things:
If you've ruled out all of the above, then Unicode characters (including Japanese) are being converted into a format that is not understandable.
Upvotes: 1