views:

607

answers:

2

On the web pages in our app, the trademark symbol (TM) is appearing as a questions mark. The registered trademark (R) works, though. We are displaying the value using the c:out tag in the JSP standard library. If I put ™ or ™ on the page to test this, those show up as they are supposed to.

<td><c:out value="${item.description}"/></td> <!-- does not work -->
<td>yada yada yada Spiros&trade; yada yada yada</td> <!-- works -->

To add to this, we're also using YUI, and before we display these pages, they show up in a YUI data table as the results of a query (the user clicks on a row to go to the page described above). The (TM) shows up properly in that table. That tells me that we are properly fetching the value from our database, and as well the server code generating the XML to send back to the YUI data table also works.

So why is the same String displayed properly in the YUI data table, but not in a normal JSP, unless we hardcode the symbol onto the page?

A: 

When a char appears as ? inside a browser (usually Firefox) it means that page encoding (as it's detected by the browser will not recognize the char. A good test would be to View->Character Encoding->UTF-8 in firefox. If the char appears correctly then it means that the (tm) char is encoded using UTF-8 standard. You have to instruct your page to set the response encoding header to UTF-8. This should work right now for you.

If that would not work you should first find out how is the character encoded (look at what encoding is read from the database for example) and try to set the page encoding header to that encoding.

The second format works because the (TM) char is encoded as a known html entity which the browser interprets regardless of the page encoding.

Toader Mihai Claudiu
There is no such thing as "encoded using unicode" Unicode is a character set, not a encoding. You appear to be conflating Unicode and UTF-8.
Matthew Flaschen
True :-). Got carried away. Edited.
Toader Mihai Claudiu
+1  A: 

You probably have an encoding issue. If you do not have an explicit encoding in your JSP:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

then it's time to add one. Try UTF-8 and if that doesn't work try ISO-8859-1 ... or if you know the correct encoding, use that.

Eddie
I had not added those. When I did, voila, it worked. Thanks!
Gary Kephart