I am running WebObjects 5.3 in Tiger, with MySQL 4.1. I am having trouble getting UTF-8 contents in my .wo files to play together with the UTF-8 data in mysql database, I am hoping someone can help me.
If I have UTF-8 data in mysql database, all I have to do is to insert the following method in Application.java ,
public void appendToResponse(WOResponse aResponse, WOContext aContext){
aResponse.setHeader("text/html; charset=UTF-8", "Content-Type"); super.appendToResponse(aResponse, aContext); }
I think this method will make the browser to treat the content retrieved or submitted as UTF-8 data, and this allows me to retrieve and insert UTF-8 data properly from and to the database. However, the above code is not enough if i also have UTF-8 data in my .wo files, after searching from the net, I found that I need to add these methods,
public void appendToResponse(WOResponse aResponse, WOContext aContext){ aResponse.setContentEncoding(_NSUtilities.UTF8StringEncoding); aResponse.setHeader("text/html; charset=UTF-8", "Content-Type"); super.appendToResponse(aResponse, aContext); }
public void takeValuesFromRequest(WORequest aRequest, WOContext aContext){ aRequest.setDefaultFormValueEncoding(_NSUtilities.UTF8StringEncoding); aRequest.setFormValueEncodingDetectionEnabled(true); super.takeValuesFromRequest(aRequest, aContext); }
Unfortunately, the above two methods (i think aReponse.setContentEcoding in particular), break UTF-8 data handling, the data retrieved is shown as rubbish, and inserted as question marks (???).
I have tried playing around with JDBC Url
jdbc:mysql://localhost/mydb jdbc:mysql://localhost/mydb?useUnicode=TRUE&characterEncoding=utf8
But none of the above seems to fix the problem.
So currently I am only able to get UTF-8 to display from either .wo or database, but not both. If anyone can share experience in UTF-8 in WebObjects, it would be very much appreciated.
Jim
|