Riccardo Cohen wrote:
I have an utf-8 html form that searches in the database, and produces result in an utf-8 html page. I have 2 conversion problems :

1) displaying items

response.setContentType("text/html;charset=utf-8") may be enough. It will set the response writer/output stream conversion to utf-8.

How do you convert a string to utf8 ?
utf8bytes = name.getBytes("UTF8") gives you the UTF-8 output.  If you pass that 
directly to response.getOutputStream() that should be it.  Don't try to convert it back 
to a String once you have done the UTF-8 encoding.  If your view is dealing with strings 
or characters instead of bytes, let the view take care of the UTF-8 encoding.  If your 
view is JSP there are page directives for this.  If your view relies or 
response.getWriter() setting the desired charset in the content type should be enough.  
If your view relies on response.getOutputStream() you need to take care of it yourself, 
buy you also will write bytes to the output, not characters.

in the form I receive a string wich is encoded in utf8 by the browser, but it is not recognized as utf8 by the server.

You may want to specify what character encoding your resin environment expects <http://caucho.com/resin/doc/env-tags.xtp#character-encoding> . Browsers typically return the form data encoded by whatever character set the html document holding the form had, so if you present your form in UFT-8 you can be reasonably sure you get utf-8 data back in the submission. Just make sure you indeed have UTF-8 data in the form, with a GET request the £ (GBP) character should show up as %C2%A9.

I cannot convert it to  utf8 for mysql.

Let the mysql JDBC driver get the String, it will deal with any UTF-8 encoding internally by itself. Don't try to force it.


resin-interest mailing list

Reply via email to