> I'm confused about what I've heard about internationalization with JSPs.  What I
> want to do is write one JSP file, and read the character set and user-visible
> text from a ResourceBundle.  This works with HTML templates, as long as the
> .properties files for the ResourceBundles are in the right codepage.  (The HTML
> markup is in ASCII, no matter what character set the user-visible text uses.)

You should be able to set the encoding to UTF-8, and be safe. Also, according
to the spec, if the JspWriter is "buffered", you can legally call
setContentType/setLocale before the buffer is flushed. I know this works
in Apache JServ, but I don't know if it works in other servlet engines.


> But what I'm hearing on the one hand is that the JSP itself has to be compiled
> with the same character set or codepage as the user-visible text.  That would
> mean that I would have to compile the JSP several times, once for each character
> set.  Is this correct?

 I don't see why. All content is just converted to out.print(), thus, as long
as the proper encoding is set, it should work. The difficulty would come about,
if you had some hardcoded non-localized text. For instance, imagine you
had a hardcoded shift-jis japanese signature in the footer in the page,
but your ResourceBundle wanted to print Hebrew, and you set the charset to
be Hebrew. You're probably get an exception.


> The other, conflicting thing I have heard is that you don't have to recompile
> the JSP, but that you do have to create a special "out" writer (using Java
> embedded in the JSP) and tell it what character set or codepage to use.  Is this
> correct?

Theoretically, all you need to do is set buffering on the JspWriter, and/or
make sure you call setContentType() before you output significant amounts
of data. JspWriter (the "out" stream), is supposed to lazily call
ServletResponse.getWriter() which postpones the point-of-no-return
in which the HTTP headers can no longer be altered.

see Jason Hunter's Rosetta Stone example

http://www.servlets.com/jsp/examples/ch12/HelloRosetta.java

I'm unsure why Jason uses his own PrintWriter rather than call
response.getWriter(), but it's probably because the code was
written before getWriter() was added to the Servlet spec.


-Ray

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to