Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JSP & utf-8

  Asked By: Bonni    Date: Oct 03    Category: Java    Views: 1082
  

I have written a farsi JSP project with MySql, hibernate And Struts. To enable farsi in project I have set
(Almost I have read all the group emails about farsi problem and jsp)

1. MySql charset to utf-8 for DB and all tables
2. request and response Charset to utf-8 (before any processing)
3. the default locale to fa-ir
4. My editor is utf-8 editor
5. My browser Encoding is utf-8
6. I have used META tag, too

BUT...
When I try to type farsi text in html forms the characters written to DB are strange characters. I tried reading string in Debug session, but I was not Successfull...
please help me to find where is the problem and the appropriate solution.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Ayaz Hashmi     Answered On: Oct 03

you should have this code in your pages :
<head>
<META http-equiv="Content-Language" content="fa">
<META http-equiv="Content-Type" content="text/html;
charset=utf-8">
</head>
and in your MySQl's my.ini file in [mysqld] section ,
you should have :
default-character-set=utf8
or you can set utf8 encoding  in your sql code.
then in your hibernate  configuration file you should
have the properties :
useUnicode=true
characterEncoding=UTF-8
then insert an init param in your web.xml <servlet>
tag

<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>

and save your pages in utf-8  format.
this will work well , but if you have a form that have
file upload and you are using a multipart form , your
unicode data will loose , and you should seperate your
form into two section , in one section get unicode
data and in one section upload your files.

 
Answer #2    Answered By: Zane Thompson     Answered On: Oct 03

put javax.sevelet.jar in classpath
&
write in controller this " request.setCharacterEncoding("UTF-8"); "

 
Answer #3    Answered By: Constance Reid     Answered On: Oct 03

Thanks to your guides, my problem  was not any of them
you considered, My MySqlServer setup and ini file was
correct and also, I have not any problem in my editor,
jsp or in Struts code.
The problem was in Tomcat server:(
In administration page (/admin) there is a "Connector
(8080)" node under
-"Tomcat Server"
----"Service (Catalina)"
--------"Connector (8080)"
which has following two properties:
URI Encoding:
Use Body Encoding For URI Query
Parameters:(true/false)
I set the values to "utf-8" and "true" and NOW...
Everything is going well.

 
Answer #4    Answered By: Este Ferrrari     Answered On: Oct 03

The best workaround for this problem  is using an encoding  filter which
reads all request  and changes the encoding to your favorite one, so
you don't have to change the tomcat parameter or jvm parameter. it's
the solution  you can find  it in sun's pet store as EncodingFilter.java

 
Didn't find what you were looking for? Find more on JSP & utf-8 Or get search suggestion and latest updates.




Tagged: