This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Since some days ago I’ve been trying to solve the following problems:
In a Web application Spanish characters like don't display the right way.
I’m using Hibernate 3.2.5, JSF 2.1, Java EE 5, Tomcat 6, Oracle 10g.
In the client
In the hibernate.cfg.xml
Seeking for solutions I tried to change the Oracle NLS_CHARACTERSET WE8ISO8859P1 to NLS_CHARACTERSET AL32UTF8 but it didn't work.
Now I notice a weird behavoir: When a client data is update using ajax the Spanish character are saved correctly, but when all the form is updated is saved the wrong way. I don't how to do. If someone can help me I'd be very grateful.
I believe the article also talked about data types and adding a property to the datasource in your context.xml. However that is a moot point since it seems you say the data is being stored correctly in the database. Is it also correct when you read it out of the database? Set a break point and check it after reading it out of the database (before the browser gets it) and see if it is still correct. If it is the problem is not with Hibernate.
Joined: Jul 30, 2005
Hello again Bill Gorder
Is it also correct when you read it out of the database?
So the problem is when sending the data to the database. What should I check? the server?
Finally after trying out various means or theories by trial and error I got the following solution:
I created a filter to encode the character set for response/request. In the request was the problem since the browser (or server?) was changing the enconding when updating the form. No change needed to the database.
But in the web.xml
To be honest I don't undestrand very well this solution but was the only one I found. I hope it doesn't bring me side effects.
That looks right. But just one comment: since you are hard-coding "UTF-8" into the Java code of your filter, that means that you don't need to specify it as an init-param of the filter. You aren't using that init-param in the code so you really ought to delete it from the web.xml file.
(Note: I'm not complaining about hard-coding "UTF-8" into the Java code. I did the same thing myself. I'm just complaining about the unnecessary parameter in the web.xml. And even that's a tiny tiny complaint.)
Joined: Jul 30, 2005
since you are hard-coding "UTF-8" into the Java code of your filter, that means that you don't need to specify it as an init-param of the filter.
Yes Paul, you are absolutely right!
The little problem I didn't mention is that I was trying to catch the parameter ("encoding" from web.xml) in the overriding init method of SetCharacterEncodingFilter class but it didn't work so, when I hard-coded "UTF-8" and I saw the right result I felt so exciting than I couldn't help to tell the world about it. Thanks for your cooperation and I will heed your advice.
P.S. English is not my mother tongue.