Discussions
Web tier: servlets, JSP, Web frameworks: Encoding non english characters with utf 8 on jsp (Critical!!)
-
Encoding non english characters with utf 8 on jsp (Critical!!) (3 messages)
- Posted by: Rajendra BN
- Posted on: June 06 2008 03:28 EDT
I am inserting hebrew characters from JSP into oracle db and everything is fine until this point. But when I try to retrieve the information from the database, the characters are not displayed properly (I get some garbage characters). I am sure that the data stored in the database is correct, but not sure why there is a problem in displaying the data in the JSP. I came across a thread on TSS https://www.theserverside.com/discussions/thread.tss?thread_id=28944 and followed the suggestions given there like having <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> and also this <% //Some JDBC and sql statement query UTF-8 data and then ... String str = rs.getString("utf8_data"); str = new String(str.getBytes("ISO-8859-1"),"UTF-8"); %> <%= str %> Now, the data getting displayed is partly correct, I mean to say, some characters are still coming as squares. Any ideas will be of great help.Threaded Messages (3)
- Re: Encoding non english characters with utf 8 on jsp (Critical! by Regunath B on June 11 2008 05:41 EDT
- Re: Encoding non english characters with utf 8 on jsp (Critical! by Jyothish John on June 12 2008 10:22 EDT
- UTF-8 Character issue while doing request.getParameter in servlet by param sethi on August 03 2009 06:53 EDT
- Re: Encoding non english characters with utf 8 on jsp (Critical! by Jyothish John on June 12 2008 10:22 EDT
-
Re: Encoding non english characters with utf 8 on jsp (Critical![ Go to top ]
- Posted by: Regunath B
- Posted on: June 11 2008 05:41 EDT
- in response to Rajendra BN
Hi, If you are sure that the data inserted into the Oracle DB is correct, you need not do any conversions on the way out. See this link : http://java.sun.com/developer/technicalArticles/Intl/HTTPCharset/ Btw, did you make sure that the column type was NVARCHAR and you used something like below to insert the data? PreparedStatement pstmt = con.prepareStatement("INSERT INTO i18n VALUES (?,?,?)"); pstmt.setLong(1, id); // number column pstmt.setString(2, "name"); // VARCHAR2 column ((OraclePreparedStatement)pstmt) .setFormOfUse(3, OraclePreparedStatement.FORM_NCHAR); pstmt.setString(3, "some unicode string"); // NVARCHAR2 column -
Re: Encoding non english characters with utf 8 on jsp (Critical![ Go to top ]
- Posted by: Jyothish John
- Posted on: June 12 2008 10:22 EDT
- in response to Regunath B
What is the encoding of your browser? UserDefined? or UTF-8? Please check your browser settings. -
UTF-8 Character issue while doing request.getParameter in servlet[ Go to top ]
- Posted by: param sethi
- Posted on: August 03 2009 06:53 EDT
- in response to Jyothish John
Hi Guys, This is regarding the issue I am facing while sending UTF-8 characters using GET method to a servlet directly from browser. I have done the following settings: 1. Created a CharsetFilter, which sets encoding type for each request as UTF-8 2. Applied this filter in web.xml before all the requests 3. In my servlet, while writing the response, I have set response.setContentType to text/html;charset=utf-8 For the above mentioned settings accented characters like ÀÃ?ÅÆÇÈÉÊËÌÃ?ÃŽÃ?Ã?ÑÒÓÔÕÖØÙÚÛÜÃ?Þßà áâãäåæçèéêëìÃîïðñòóôõöøùúûüýþÿ works correctly. But Chinese characters, Arabic characters etc does not work. How ever if along with above settings, I change the server.xml settings to have useBodyEncodingForURI="true" OR/AND URIEncoding="UTF-8" in connector tag, the Chinese & Arabic characters works fine but now accented characters do not work . I have tried all the combination of the settings mentioned but some how only one of the above two situations work. Has anybody come across this problem? Any pointers will be great. I can not use POST request, as My servlet is the entry point to my application. Thanks Param