views:

662

answers:

3
+3  A: 

but does not render in the jsp/browser?

You need to set the response encoding as well. In a JSP you can do this using

<%@ page pageEncoding="UTF-8" %>

This has actually the same effect as setting the following meta tag in HTML <head>:

<meta http-equiv="content-type" content="text/html; charset=utf-8">
BalusC
When I try to print the contents of the java string variable on the console by using System.out.println(...), I see "?" instead of right arrow so my guess is that JSP gets question marks that is why it displays question marks in the browser. And I think that the problem is within my java code and maybe I have to specify encoding of the String content in some other way.
m_a_khan
Then the console should also be configured to use UTF-8. You can find more background information and detailed solutions here: http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html Hope this helps.
BalusC
+1  A: 

Possibilities:

  1. The browser does not support UTF-8
  2. You don't have Content-Type: text/html; charset=utf-8 in your HTTP Headers.
Dylan Lacey
A: 

The lazy developer (=me) uses Apache Common Lang StringEscapeUtils.escapeHtml http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringEscapeUtils.html#escapeHtml%28java.lang.String) which will help you handle all 'odd' characters. Let the browser do the final translation of the html entities.

Kennet