Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

� displayed as ?  RSS feed

 
John Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen this post several times on various forums but never seen a satisfactory answer so I'm hoping someone can help. Within a JSP, I am trying to display a euro sign in a browswer by converting the ascii code for a euro as follows (the ascii code is actually coming from another method but I've hardcoded it for ease of reading) :

int currencyAsciiCode = 8364;
String formattedNumber = df.format(toFormat);
char[] asciiChar = {(char)currencyAsciiCode};
String asciiCharString = new String(asciiChar);

Within JBuilder, the code seems to work fine but by the time it hits the browser the � has become a ?. Unfortunately I can't use € in its place because the code sits in a pool of shared code & the result may not be viewed via a browser. Ihave played about with various things like getting the currency from locales but the result is the same each time.

I can only presume that there is some kind of character translation at work between the server & the browser but I have no idea where (If it's of any significance, the resultant string is being used within a Struts framework)
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you can simplify that code to this:Second, to answer your real question, yes there is some character translation going on, and it obviously isn't the translation you want to be going on. Most likely your app server's default for the page encoding is ISO-8859-1 or some other encoding that doesn't include the Euro character. UTF-8 is a good choice because all browsers can support it. Put this directive in your JSP:Or I think you could avoid the whole encoding question by using the HTML escape for the Euro character:

[ October 20, 2005: Message edited by: Paul Clapham ]
[ October 20, 2005: Message edited by: Paul Clapham ]
 
John Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, thanks fopr the reply. I have taken on board your suggestion of simplifying the code by using the Unicode value & everything works fine if I add the <%@ page contentType="text/html; charset=UTF-8" %> directive in the JSP.

However, I would like this to apply to all JSPs and am looking for a global setting. Both the web.xml & struts-config files have the following entry <?xml version="1.0" encoding="UTF-8"?> but I presume this applies only to the coding of the files themselves?? Any advice on how I can effectively add this directive without explicitly adding it directly to each JSP page?
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try configure the page encoding using the jsp property group in web.xml as follows:



Hope it helps.
 
John Harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eddy, thanks for the suggestion. Can you give me some more details as to where within the web.xml this needs to appear. My web.xml doesn't seem to like it anywhere?? Could it be a version issue?
Regards
John
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It only works with JSP2.0 and above. Refer to JSP 2.0 Specification Part 3: JSP Configuration.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!