Question

I'm using the following JSoup code to render this currency:

currencySpan.html("€" + currencyFormat.format(estimatedValue));

However if you visit http://www.lastcalc.com/pmGgp1QR to see the output of this, it is displaying a '?' where the Euro symbol should be (before the 19.164 value). I see this in both Chrome and Safari.

Why is this symbol not being displayed correctly?

edit: People are pointing out that this isn't a browser issue, rather the ? is being served up. Basically I'm using JSoup's Element.html() to set the text (which includes the %euro;), and from there I use JSoup to render it to a string, which is returned to the browser (either directly when the page first loads, or as part of an AJAX JSON call if the page is edited).

This is the code that returns the document (resp is a HttpServletResponse):

resp.setContentType("text/html");
resp.getWriter().append(doc.toString());

edit2: I stuck a System.out.println(currencySpan); in there and sure enough, Java prints:

<span class=" currency">€19.164</span>

The strange thing is that JSoup appears to have converted & euro ; to the actual symbol, yet at some point it's not getting to the browser.

How do I ensure that the browser is treating what is returned by the servlet as UTF-8?

edit3: Fixed, I answered with the fix below.

Was it helpful?

Solution

Ok, the problem was that the browser wasn't interpreting the response as UTF-8, fixed with:

resp.setContentType("text/html; charset=UTF-8");

OTHER TIPS

The &euro; symbol is not making its way to the browser. If you view the source, it is showing a ? where I would expect to see the &euro; code in the html. if you look a this ( http://jsfiddle.net/gTLKq/ ) JSFiddle code, it clearly shows the euro symbol from the entity value you are using.

Therefore, JSoup is modifying your code. Are you cleaning the JSoup output, or doing anything else that may result in JSoup doing this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top