Hi, Michael,

Thanks for sharing information.

If my understanding is correct, the solution you mentioned is for changing locale 
during a session. I have tried to use 
your code, but can't test it out since one more class is needed to get it running.

I use the lastest JSTL build as Jan suggests and the two problems are resolved. (~/

Have you encountered any situation that messages come from the server? If so, do you 
create another set of resource 
bundle?

BTW, where is a good site to find out the mapping between Chinese character and 
unicode?

Best regards,

Vernon

 
5/23/2002 2:44:17 AM, "Michael Zhou" <[EMAIL PROTECTED]> wrote:

>Regarding your second question, in our project we have <%@ page 
>contentType="text/html; charset=UTF-8" %> at 
the top of
>each jsp page. We also enable page buffering, ie, <%@ page buffer="256kb" 
>autoflush="true" %>. Then we define a 
custom
>tag to dynamically set content type and character encoding based on request. 
><i18n:setContentType /> should 
appear
>relatively early in the page, because otherwise the response would already be 
>commited otherwise. The source code 
for
>the setContentType tag is as follows.
>
>import java.util.Locale;
>import java.util.ResourceBundle;
>import java.util.MissingResourceException;
>import javax.servlet.jsp.JspException;
>import javax.servlet.http.HttpServletRequest;
>import javax.servlet.http.HttpServletResponse;
>import javax.servlet.jsp.tagext.TagSupport;
>
>/** Tag to set content type based on request. */
>public class I18nSetContentTypeTag extends TagSupport {
>    public int doStartTag() throws JspException {
>        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest ();
>        HttpServletResponse res = (HttpServletResponse) pageContext.getResponse ();
>        String charset = req.getCharacterEncoding ();
>        if (charset != null) {
>            res.setContentType ("text/html; charset=" + charset);
>        }
>        else {
>            Locale locale = req.getLocale ();
>            try {
>                // set character encoding
>                // MainProps is a class we define to retrieve application level 
>properties
>                // Here we define character encoding mappings in our properties file
>                String enc = MainProps.getValue ("CharEncoding." + locale.toString 
>(), null);
>                if (enc != null)
>                    res.setContentType ("text/html; charset=" + enc);
>                else // default to utf-8
>                    res.setContentType ("text/html; charset=utf-8");
>            }
>            catch (Throwable t) {
>                t.printStackTrace ();
>            }
>        }
>        return SKIP_BODY;
>    }
>}
>
>--
>Michael
>
>-----Original Message-----
>From: Vernon Wu [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, May 21, 2002 5:22 PM
>To: Jan Luehe
>Cc: [EMAIL PROTECTED]
>Subject: Re: Usage of i18n in JSTL
>
>
>Thanks Jan for your detailed explanation. I think I finally find the right document 
>which is under the standard-doc of
>the
>taglib.
>
>1)
>I follow the instruction and insert the line:
><%@ taglib uri="http://java.sun.com/jstl/ea/fmt"; prefix="fmt" %>
>in a JSP file, and the lines:
>
>       <context-param>
>               <param-name>javax.servlet.jsp.jstl.i18n.basename</param-name>
>               <param-value>mm</param-value>
>       </context-param>
>in the web.xml file.
>
>I also have three resource files in place: mm.properties, mm_en.properties, and 
>mm_zh.properties.
>
>I get an exception when I try to bring up the jsp page (see the error message on the 
>bottom).
>
>After I replace the format tag lib of JSTL with the followings:
>
><%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0"; prefix="i18n" %>
>
><i18n:bundle baseName="mm"
>             id="bundle"/>
>
>The English version displays properly under the browser language setting with ?en? 
>higher than ?zh?.
>
>To my understanding, the code base of i18n and fmt tag libraries are the same (You 
>wrote it). I guess the problem is 
the
>setting. Would you please point out where I did wrong.
>
>2)
>When 'zh' is higher than 'en' in the browser's language setting, all messages in the 
>resource file are displayed as ???.
>And I find out the locale and character setting on the page is en_US and ISP-8859-1 
>respectively. All jsp files have 
the
>character set as UTF-8 since each jsp file started with <%@ page 
>contentType='text/html; charset=UTF-8' %>. All JSP
>file is formed from several regions: banner, side bar, footer, and body.
>
>How can I have the right locale and character set in the JSP file?
>
>Thanks very much for your kindly help.
>
>Vernon
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>2002-05-22 04:41:41 ApplicationDispatcher[/mm] Servlet.service() for servlet jsp 
>threw exception
>javax.servlet.ServletException: org/mozilla/javascript/JavaScriptException
>       at 
>org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:463)
>       at org.apache.jsp.content$jsp._jspService(content$jsp.java:346)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
>       at 
>org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:819)
>       at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:391)
>       at com.vernonwu.waf.view.template.Section.render(Section.java:41)
>       at com.vernonwu.waf.view.template.tags.RenderTag.doEndTag(RenderTag.java:57)
>       at org.apache.jsp.hscf02$jsp._jspService(hscf02$jsp.java:137)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
>       at 
>org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:819)
>       at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:391)
>       at com.vernonwu.waf.view.template.Region.render(Region.java:35)
>       at com.vernonwu.waf.view.template.tags.RenderTag.doEndTag(RenderTag.java:61)
>       at org.apache.jsp.page$jsp._jspService(page$jsp.java:1480)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
>       at 
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
>       at 
>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at 
>org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
>       at 
>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at 
>org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at 
>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1017)
>       at 
>org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1115)
>       at java.lang.Thread.run(Thread.java:536)
>----- Root Cause -----
>java.lang.NoClassDefFoundError: org/mozilla/javascript/JavaScriptException
>       at java.lang.Class.forName0(Native Method)
>       at java.lang.Class.forName(Class.java:130)
>       at 
>org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.getEvaluatorByName
>(ExpressionEvaluatorManager.java:219)
>       at org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate
>(ExpressionEvaluatorManager.java:183)
>       at 
>org.apache.taglibs.standard.tag.el.core.ExpressionUtil.evalNotNull(ExpressionUtil.java:85)
>       at 
>org.apache.taglibs.standard.tag.el.fmt.MessageTag.evaluateExpressions(MessageTag.java:159)
>       at 
>org.apache.taglibs.standard.tag.el.fmt.MessageTag.doStartTag(MessageTag.java:108)
>       at org.apache.jsp.content$jsp._jspService(content$jsp.java:192)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
>       at 
>org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:819)
>       at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:391)
>       at com.vernonwu.waf.view.template.Section.render(Section.java:41)
>       at com.vernonwu.waf.view.template.tags.RenderTag.doEndTag(RenderTag.java:57)
>       at org.apache.jsp.hscf02$jsp._jspService(hscf02$jsp.java:137)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
>       at 
>org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:497)
>       at 
>org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:819)
>       at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:391)
>       at com.vernonwu.waf.view.template.Region.render(Region.java:35)
>       at com.vernonwu.waf.view.template.tags.RenderTag.doEndTag(RenderTag.java:61)
>       at org.apache.jsp.page$jsp._jspService(page$jsp.java:1480)
>       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
>       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
>       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
>       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>       at 
>org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
>       at 
>org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
>       at 
>org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at 
>org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
>       at 
>org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at 
>org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at 
>org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
>       at 
>org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
>       at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
>       at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
>       at 
>org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1017)
>       at 
>org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1115)
>       at java.lang.Thread.run(Thread.java:536)
>
>5/18/2002 5:57:35 AM, Jan Luehe <[EMAIL PROTECTED]> wrote:
>
>>Vernon:
>>
>>> To my understanding, when I use the i18n tags from JSTL, I don't
>>> need to write any class to get locale information stored. Only task
>>> is to configure the locale information file. Please point it out if
>>> I am wrong.  If I need to use the PropertyResourceBundle class as
>>> the followings (this class, according to the JDK document, can't be
>>> subclassed by the way):
>>
>>I never suggested you subclass PropertyResourceBundle. I said that
>>JSTL's I18N tags work with any subclass of java.util.ResourceBundle,
>>and the JDK happens to provide two subclasses: ListResourceBundle and
>>PropertyResourceBundle. I mentioned that only in the unlikely case
>>that neither of these fit your needs would you have to provide your
>>own subclass of ResourceBundle (not PropertyResourceBundle).
>>
>>When using PropertyResourceBundle, all you need to provide is a
>>properties file containing key/value pairs. PropertyResourceBundle has
>>a constructor which takes an InputStream from which the properties
>>file is read.
>>
>>For example, if you had this JSP fragment:
>>
>>  <fmt:setLocale value="en-US" />
>>  <fmt:setBundle basename="com.acme.resources.Resources" />
>>  <fmt:message key="greeting" />
>>
>>you would need to provide the following resource with your web application:
>>
>>  com/acme/resources/Resources_en_US.properties
>>
>>with these contents:
>>
>>  greeting=Hi
>>
>>You can also take a look at the standard-examples web application that
>>ships with the JSTL reference implementation. It contains example
>>pages that have been internationalized into German and Italian, and bundles
>>the corresponding properties files containing the German and Italian
>>localized messages.
>>
>>> At this point, I am very frustrated by the fact of lacking JSTL
>>> documentation. I have searched all possible places and not much
>>> helpful information available. The document comes with JSTL doesn't
>>> help much. And the jwsdp document mentions JSTL, but still not much
>>> on i18n. I guess that I shall use i18n tags other than
>>> JSTL.
>>
>>Please note that JSTL leverages the I18N support provided by the JDK.
>>on which there is a good tutorial at:
>>
>>  http://java.sun.com/docs/books/tutorial/i18n/
>>
>>Also, 3 books (that I am aware of) covering JSTL will be out shortly.
>>
>>
>>Jan
>>
>>
>>
>>
>
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to