Hello Jason!

> To All JSP Interest,
>
>    I need to do web page, which have mutli-version's charset. That mean I
> can click a button to change to "chinese" or "english" wording. But I try it
> is hard to make a dynamic charset on jsp? How can I solve this problem?
> Please anyone help?

I have been struggling to do exactly the same!
This is what i have found out:

it is possible for Tomcat if the jsp page
has buffering on.
it is impossible for tomcat if the jsp page
has buffering off.
it is impossible for Weblogic 6.0sp1
with buffering both on and off.

for tomcat you should do
<% response.setContentType("text/html; charset=xxx"); %>

not to write it all over again i include the test of message i have sent
to [EMAIL PROTECTED] today, here it is:

---------------------
Hello, the Team!

Thanks for the GOOD JOB your've done on these specs,
they're GREAT!

Still, feel further contributions to the JSP technology
may be made:

1. PROBLEM ====================================

While trying out the org.apache.taglibs.i18n tag library
found out one _very sad_ thing, a current limitation of
the JSP technology:

there's no reliable and portable way to
DYNAMICALLY SET THE CHARSET OF THE PAGE :-((

In tomcat 4.01 it is possible, if you write ru.jsp:

<%@ page buffer="16k" %>
<%
   response.setContentType("text/html; charset=windows-1251");
%>
<%--emmit "Hello!" in russian --%>
<%="\u041f\u0440\u0438\u0432\u0435\u0442!"%>

this will work:
1) Content-Type=text/html; charset=windows-1251
2) proper single-byte cyrillic characters will be emmited

but if we try the same code on Bea Systems Weblogic server
version 6sp1, we will have
1) Content-Type=text/html; charset=windows-1251 (ok)
2) characters are malformed

It is easy to see why this happens: the servlet
spec says that we should do response.setContentType()
before the response.getWriter() and the code
that jsp containers generate for our ru.jsp
first does

response.setContentType("text/html;charset=ISO-8859-1");

then

out = pageContext.getOut();

and only then any our code in the jsp page gets a chance
to be executed. We should guess that Weblogic's
pageContext.getOut() does response.getWriter()
somewhere internally and this perfectly agrees with the
spec.
Even tomcat behaves the same way if we set buffer="none"...

2. HOW MUCH NEED THERE IS TO SET CHARSET DYNAMICALLY

I personally beleive there is some need to do that.
Being multiligual is extremely important for web
applications and limitation to only single charset
looks too constraining. Even for a single language
like russian or japaneese there may exist multiple
encodings, and if you have to make your page
being either Swedish or Russian there's no other
option currently left apart from going utf-8,
It's a way out, but still it is not always desiarable,
i beleive we should have an option wether to use utf-8
or not in this case.

3. SOLUTION ==========================================

This issue looks quite hard to fix :-(
The only solution that i can see is to
intorduce some other tipe of scriptlets, something
like

<%~  %>

that would execute after all the page implicit
objects have been created and intialized
except for the out object.

---------------------
Best regards,
 Anthony Tagunov mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to