views:

312

answers:

5

I'm having some internationalisation woes:

My UTF-8 string fields are being rendered in the browser as ???? after being returned from the database.

After retrieval from the database using Hibernate, the String fields are presented correctly on inspection using the eclipse debugger.

However Struts2/Tiles is rendering these strings as ???? in the HTML sent to the browser.

The charset directive is present in the HTML header:

Perhaps I need to add something to my struts2 or tiles configurations?

A: 

Try setting the lang attribute on the <html/> element.

HTML example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html lang="ja"> 

XHTML example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja"> 
bmatthews68
A: 

You could try something like this.

It's taken from sun's page on Character Sets and Encodings. I think this has to be the very first line in your jsp.

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

Thanks guys.

Sadly doing this hasn't helped.

Ash Kim
+1  A: 

OMG - it turns out that the cause was a total WTF?

all our tile responses were being served by a homegrown servlet that was ignoring the

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

directive (and who know what else).

TilesDispatchExtensionServlet : bloody architecture astronauts, i shake my fist at ye.

Ash Kim
A: 

You need to use a filter. See:

http://wiki.apache.org/tomcat/Tomcat/UTF-8