tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Murray Steele <mur...@peoplesarchive.com>
Subject Re: Problem with <fmt:bundle>
Date Wed, 22 Mar 2006 10:13:02 GMT
Hi,

I ran up against this problem in my application.  After some digging I 
boiled it down to the fact that the servlet spec / tomcat versions I 
was using didn't allow me to provide a Locale to character encoding 
mapping, and when the fmt tags do pretty much anything, they end up 
setting the Locale, which in turn sets the character encoding.  I think 
I read somewhere that some version of the servlet spec allows you to 
specify Locale to character encoding mappings in the web.xml file, but 
for what I'm using (2.3 on tomcat 4.1) what I had to do was create a 
custom CharSetMapper and specify it on the <context> tag in my 
server.xml.

My charset mapper ignores whatever locale you ask for a mapping for and 
returns UTF-8 as the charset every the time.  It seemed extreme, but 
it's what I wanted.  I compiled this and put it in 
<tomcat_home>/server/classes/

UTF8CharSetMapper
--
package com.peoplesarchive.tomcat;

import java.util.Locale;

import org.apache.catalina.util.CharsetMapper;

public class UTF8CharsetMapper extends CharsetMapper {
     public UTF8CharsetMapper() {
         super();
     }

     public UTF8CharsetMapper(String name) {
         super(name);
     }

     public String getCharset(Locale locale) {
         return "utf-8";
     }
}

server.xml fragment
--
<Context 
charsetMapperClass="com.peoplesarchive.tomcat.UTF8CharsetMapper" 
path="" docBase="ROOT" debug="0" reloadable="true" />

hope this helps

Muz

On 22 Mar 2006, at 09:43, ilanchezhian ganesamurthy wrote:

> Hello,
>
>   I have problem while displaying of japanese UTF-8 character.
>   I set response header character encoding to UTF-8 by  <%@ page 
> contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" %> then I 
> read the UTF-8 japanese character by following statement
>
>   <fmt:bundle basename="com.xxx.myBundle">
>       <fmt:message key="k1"/>
>   </fmt:bundle>
>
>   Even though i set response character encoding to UTF-8 but when 
> compiler start executing <fmt:bundle> it automatically chages response 
> character encoding to 'Shift_JIS' from 'UTF-8' I can notice this by 
> printing response character encoding before and after <fmt:bundle>. 
> Due to this form is not displayed properly. I dont have issue with 
> locale, I have only issue with response character encoding.
>
>   Resource bundle contains UTF-8 character
>   I have followig jsp
>
>   <%@ page contentType="text/html; charset=UTF-8"  
> pageEncoding="UTF-8" %>
>  <%@ taglib uri="fmt" prefix="fmt" %>
>   <html>
>  <head>
>  </head>
>     <%System.out.println("CharacterEncoding before calling fmt = 
> "+response.getCharacterEncoding() );%>
>
> <fmt:bundle basename="com.xxx.myBundle">
>   <%System.out.println("CharacterEncoding after calling fmt = 
> "+response.getCharacterEncoding() );%>
>
>     <fmt:message key="k1"/>
>   </fmt:bundle>
>    </html>
>
>   You can see result o/p to
>
>   CharacterEncoding before calling fmt = UTF-8
>   CharacterEncoding after calling fmt = Shift_JIS
>
>   Cheers
>   ilan
>
>
>
> 				
> ---------------------------------
>  Jiyo cricket on Yahoo! India cricket
> Yahoo! Messenger Mobile Stay in touch with your buddies all the time.
--
Murray Steele
Head of Development

Peoples Archive
w: http://www.peoplesarchive.com
t: 0207 323 0323
d: 0207 631 9147

This email has been scanned by Postini.
For more information please visit http://www.postini.com


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message