Displaying chinese characters in browser
Dear sirs,
I am having the following issue in chinese internationalization.when i stored the JSP form parameters(typed in chinese) in database,it stored some kind of junk characters ....and when i displayed ,they showed like SMALL SMALL tables.... in my browser.
Our project is java based web application.
Java-1.5
Mysql-5.0.24
tomcat-5.5
JSP-1.2
servlet-2.0
browser-mozilla firebox
I set in my all JSP pages,
-->1.<%@ page contentType="text/html;charset="UTF-8" pageEncoding="UTF-8"%>
-->2.<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
in my JAVA files,i added,
-->String encode=ServletContext.getInitParameter("javaEncoding");
-->request.setCharacterEncoding(encode); (it gets encoding UTF-8 from web.xml file)
In my MYSQL,i set...
-->mysql --default-character-set=utf8 -username -password -database
so,i changed client,connection,results,system charactersets " utf8" and connection collation is "utf8".
In my DATABASE connection String...i added,
>useUnicode=true&characterEncoding=UTF-8
In my TOMCAT web.xml file..i added these lines as i am using POST method for form.
<context-param>
<param-name>javaEncoding<param-name>
<param-value>UTF-8<param-value>
<context-param>
still .i am unable to display chinese characters in my browser.
but.when i am using getBytes() for all form parameters in JAVA file....i m able to store chinese in db and dispay in browser ....
String param;
->String param=newString(param.getBytes("ISO8859-1"),"UTF-8");
Could anyone tell me another method for displaying chinese except this getBytes()..
please help me out. i am trying to find out an alternative server-independent method for past two weeks.
Advance thanks for reading and help.
mullaimaran.
It looks as if you are doing everything correctly. Have you tried passing the form parameters from one JSP to another (no DB storage), and do the characters display correctly in that case? If they do, it would narrow the problem down to the database connection or the database
Hi...
Thank you for reply...
I tried what you had explained.
but,still chinese characters are not displayed...properly.
It displayed small square boxes ..only..i dont know what i am missing?
is my database configuration enough?or should i modify tomcat configuration?
please help me...
mullaimaran.
OK, if I understand your reply correctly, you do not get the Chinese characters displayed correctly if you enter them in a form on one JSP page and display them on another JSP page - without storing them in the DB in between?
This would indicate that there is something wrong with your servlets/JSPs/Tomcat environment.
I have that working fine, using the same components as you, but I specify
request.setCharacterEncoding("UTF-8");
in the JSP, instead of using the web.xml and JAVA file configuration. Have you tried doing that?
Hi...
Thanks for your reply.
WHEN i entered CHINESE in a form on one JSP page and display them on another JSP page ,I successfully displayed chinese characters (with out DB Strorage) now.
As our project uses jsp for presentation and java(servlet) for logic part ....(MVC2)
i tried in JAVA file(servlet) with DB storage,i could not display chinese.
still i get small square boxes only( i also set
request.setCharacterEncoding("UTF-8");
in my jsp pages...)
should i change the database server and database characterset(Default is latin1) as "UTF-8"?.
mullaimaran.
> should i change the database server and database
> characterset(Default is latin1) as "UTF-8"?.
Yes, you definitely need to define the database character set as UTF-8 for this to work without the getBytes workaround you mentioned in your original post. I thought you had already done that (again, based on your original post).
I have never worked with mysql, so I don't know all the DB-specific configuration that would have to be done.
Hi one_dane,
Yes,I set the database configuration ....i.e.,i set
mysql> show variables like '%char%';
+--+-+
| Variable_name| Value |
+--+-+
| character_set_client| utf8|
| character_set_connection | utf8|
| character_set_database| latin1 |
| character_set_filesystem | binary |
| character_set_results| utf8|
| character_set_server| latin1 |
| character_set_system| utf8|
| character_sets_dir| /usr/share/mysql/charsets/ |
+--+-+
and set collation....
mysql> show variables like '%col%';
++-+
| Variable_name | Value |
++-+
| collation_connection| utf8_general_ci|
| collation_database| latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
.............buut i am still unable to display to chinese characters.
Actually .. I pass the JSP form parameters to JAVA(servlet) file...
my JAVA(Servlet) coding...
Enumeration params = request.getParameterNames();
while(params.hasMoreElements()) {
String paramname = (String)params.nextElement();
String paramvalue = request.getParameter(paramname);
.........when i print the paramvalue ....i am getting some junk characters only.not chinese.
so i think,my DB conf is enough.but problem is in my JAVA(servlet) file only.
I dont know what i m missing here?
could you help me?
mullaimaran.
It would seem to me that the relevant DB configuration parameters are set incorrectly, that is, to latin1:
> | character_set_database| latin1
> | collation_database| latin1_swedish_ci |
> | collation_server | latin1_swedish_ci |
As I said, I have never worked with mysql, but surely the parameters shown say that the DB character set is set to latin1 (8859-1)?
All the other parameters seem to have to do with the client/connection, etc., and they won't help you at all if the DB itself is configured with 8859-1.
And I thought you said that you could pass Chinese characters from one JSP to another, and they display correctly? That would indicate to me that the problem is with the DB and/or the DB connection.
> It would seem to me that the relevant DB
> configuration parameters are set incorrectly, that
> is, to latin1:
Looks that way to me. My installation of MySQL is set up this way (i.e. the default way) and when I tried to insert a Greek letter alpha into a table column, it came back as a question mark. Chinese characters would be treated the same way, I'm sure.
Hi one_dane &Mr.Clap,
Thank you for your help.
At last i displayed chinese characters with out using getBytes() and web.xml configuration.
My settings for displaying chinese....
JSP :
1<%@ page contentType="text/html;charset="UTF-8" pageEncoding="UTF-8"%>
2.<HEAD>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</HEAD>
JAVA(Servlet):
-
request.setCharacterEncoding("UTF-8");
MYSQL:
-
Mysql connection String...i added,
-> useUnicode=true&characterEncoding=UTF-8
i m using linux terminal for mysql login.
bash]$ mysql --default-character-set=utf8 -username -password -database name
So, i changed these settiings in database
mysql> show variables like '%char%';
+--+-+
| Variable_name | Value |
+--+-+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--+-+
and set collation....
mysql> show variables like '%col%';
++-+
| Variable_name | Value |
++-+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
Once again thank you....for help.Keep your assistance in this forum.
mullaimaran.
Hi,I am also facing the same problem. Please give me the solution,
Hi..Please tell me about your problem in elaborate manner.
Hi,I have some Local Language characters in UTF-8 format. How do I display them on the screen using jsp's.
I have included
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
and
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
at the top of the jsp and I have copied the encoded string in the body of the jsp.
But I dont see the conversion happening. It's getting printed in the same fashion.
How do I go abt this.
Thanks in anticipation of a response.
HiI think your settings are enough to display a local language on browser.You just show me the piece of coding in which you copied local character.I ll try to give a solution.byeS.Elamaran.