Hi,
(B
(BI'm unlucky since I live in Japan. The localization and the char encodings are
(Bdifficult problems.
(B
(BTapestry (or web container) should handle mainly following 3 issues.
(B
(BFirst(and most difficult) issue is the char encoding of query parameters
(Bas pointed. The encoding would vary depending on the character encoding of
(Bthe HTML including a form that submitted the query parameters.
(BIn my environment(Japanese Windows, Japanese IE6 or English opera7,
(BTomcat4.1), servlets get parameters encoded with UTF-8 when HTML including
(Ba form is encoded with UTF-8. Similarly, servlets get parameters encoded
(Bwith MS932 when HTML including a form is encoded with MS932. Other browsers
(Bmay behave differently.
(BSo, it is preferable to be able to specify the argument of
(BServletRequest.setCharacterEncoding() for each page locale. (Multilingual
(Bweb apps would use some char encodings)
(B
(BIn addition, setCharacterEncoding() is available only for HTTP request body,
(Bnot header(from Servlet API document). So, parameters submitted with GET
(Bmethod may be broken. Fortunately setCharacterEncoding() affect such
(Bparameters on the Tomcat implementation.(How about Jetty?)
(B
(BSecond issue is the char encoding of HTML sent to the browsers. It is
(Beasy to resolve this issue.
(B
(B1. Add "charset" property to the application/page specification like:
(B  <property name="charset">EUC_JP</property>
(B2. Override BasePage.getResponseWriter() method like:
(Bpublic class HomePage extends BasePage {
(B public IMarkupWriter getResponseWriter(OutputStream out)
(B {
(B  String charset = getSpecification().getProperty("charset");
(B  if (charset == null) {
(B   charset = getEngine().getSpecification().getProperty("charset");
(B   if (charset == null) {
(B    charset = "UTF-8";
(B   }
(B  }
(B  return new HTMLWriter("text/html; charset=" + charset, out);
(B }
(B
(BIt is better to let Tapestry be able to specify charset for each page
(Btemplate.
(B  <property name="charset_ja">EUC_JP</property>
(B  <property name="charset_de_CH">UTF-8</property>
(B
(BThird issue is the char encoding of file(i.e. page template file).
(BA page template file for "_en" locale may be encoded with the different
(Bencoding from the encoding used for "_ja" locale template file.
(BAn additional character encoding parameter is needed wherever the
(Bconstructor of InputStreamReader is used.
(BWe also need to control the character encoding by some specification file
(Bfor each page locale.
(B
(B
(BFollowing JSP is for encoding tests.
(B
(B- Vary the charset where *1.
(B- Replace the encodings where *2 with what you want.
(B- Replace the string where *3 with unicode escaped string your borwser can display.
(B- Vary the method where *4 to check your web containers behavior.
(B
(B
(B<%@ page language="java" contentType="text/html; charset=UTF-8" %><!-- *1 -->
(B<%!
(Bstatic final String[] ENCs = { // *2
(B "UTF-8", "EUC_JP", "JIS0212",
(B "SJIS", "MS932", "CP943"
(B };
(B 
(Bstatic final String dataStr = // *3
(B "abc\u03b1\u03b2\u03b3\u6f22\u5b57\u301c\uff5e";
(B%><%
(Brequest.setCharacterEncoding("ISO-8859-1");
(B%>
(B<html>
(B<body>
(B
(B<form action="iEncodingChecker.jsp" method="POST"><!-- *4 -->
(BSubmitting a following string.
(B<pre><%= dataStr %></pre><br>
(B<input type="hidden" name="str" value="<%= dataStr%>">
(B<input type="submit" value="Submit">
(B</form>
(B
(B<%
(BString str = request.getParameter("str");
(BString result = "unknown";
(Bif (str != null) {
(B byte[] bytes = str.getBytes("ISO-8859-1");
(B
(B for (int i = 0; i < ENCs.length; i++) {
(B  result = new String(bytes, ENCs[i]);
(B%><%= ENCs[i]%>: <%= result%><br>
(B<%
(B }
(B result = "";
(B for (int i = 0; i < bytes.length; i++) {
(B  result += Integer.toString((0xff & (int)bytes[i]), 16);
(B  result += ",";
(B }
(B}
(B
(B%>
(BEncoded codes of the submitted data are <%= result %>.
(B
(B</body>
(B</html>
(B
(BRegards,
(B
(BKohji Nakamura
(B
(B
(B --- Original Message
(B
(B>  Since I'm lucky enough to live in US, I don't have
(B> to deal with localization 
(B>  and code pages, so I'm a little fuzzy on the actual
(B> problem.
(B>  
(B>  What I've seen is that when I change the character
(B> encoding to UTF-8 (you can 
(B>  do this in BasePage when creating the IMarkupWriter
(B> instance) some characters 
(B>  don't render properly in IE.  This could end up
(B> being anything in the stack 
(B>  anywhere between my code, Jetty, java.io, IE or
(B> elsewhere ... or simply a 
(B>  missing font.
(B>  
(B>  
(B>  If someone would take the time to document, on the
(B> Wiki, what they need 
(B>  Tapestry to do and why we can see how to address
(B> it.  I've been thinking that 
(B>  applications and/or individual pages may want to
(B> override the default character 
(B>  encoding for responses, this could be accomplished
(B> via a specification property 
(B>  (a <property> element in the specification).
(B>  
(B>  I'm sure someone out there deals with true
(B> localization/character set/code 
(B>  page/character encoding issues daily and can
(B> educate us on what the ideal 
(B>  solution would be.
(B>  
(B>  --
(B>  [EMAIL PROTECTED]
(B>  
(B>  http://tapestry.sf.net
(B>  > 
(B>  > Hi there,
(B>  > 
(B>  > my tip:
(B>  > 
(B>  > subclass the ApplicationServlet
(B>  > and insert this method
(B>  > 
(B>  >     protected void doService(HttpServletRequest
(B> request, HttpServletResponse 
(B>  > response)
(B>  >         throws IOException, ServletException
(B>  >     {
(B>  >         request.setCharacterEncoding("UTF-8");
(B>  >         super.doService(request, response);
(B>  >     }
(B>  > 
(B>  > 
(B>  > -----Original Message-----
(B>  > From: Adam Greene [EMAIL PROTECTED]
(B>  > Sent: Freitag, 20. Dezember 2002
(B>  > To: [EMAIL PROTECTED] 
(B>  > [EMAIL PROTECTED]
(B>  > Subject: [Tapestry-developer] Outcome of problem
(B> with UTF-8 vs ISO-8859-1
(B>  > 
(B>  > AG> I have managed to figure out how to do UTF-8
(B> for everyting except input
(B>  > AG> boxes.  The problem is in this:
(B>  > 
(B>  > AG> I input "etre" into a text field, if I use
(B> JavaScript to display the value
(B>  > AG> of the field, it says "etre".  But when it
(B> arrives at the server, it is
(B>  > AG> converted to UTF-8, which ends up converting
(B> the e into a two byte
(B>  > AG> character, but not the right ones (it is
(B> actually a ISO-8859-1 conversion,
(B>  > AG> not a UTF-8.  You can see the same effect by
(B> switching Eclipse into
(B>  > AG> ISO-8859-1 mode, create an HTML, put in an e,
(B> save it and reload it, you
(B>  > AG> great screwed up text.  Switch into UTF-8
(B> mode, delete the garbage and
(B>  > AG> re-insert the e, save, reload, everything
(B> fine).
(B>  > 
(B>  > AG> What I'm wondering is:  Does anyone know how
(B> to get the result of input
(B>  > AG> fields in UTF-8, encoded properly.  I can
(B> switch the charset of the page to
(B>  > AG> ISO-8859-1 and have it return proper values,
(B> but then the dynamic data will
(B>  > AG> not display properly on the UTF-8 pages
(B> (which is the mode I need to edit
(B>  > AG> them in inorder to use Eclipse).
(B>  > 
(B>  > 
(B>  > 
(B>  > 
(B>  > AG>
(B> -------------------------------------------------------
(B>  > AG> This SF.NET email is sponsored by:  The Best
(B> Geek Holiday Gifts!
(B>  > AG> Time is running out!  Thinkgeek.com has the
(B> coolest gifts for
(B>  > AG> your favorite geek.   Let your fingers do the
(B> typing.   Visit Now.
(B>  > AG> T H I N K G E E K . C O M       
(B> http://www.thinkgeek.com/sf/
(B>  > AG>
(B> _______________________________________________
(B>  > AG> Tapestry-developer mailing list
(B>  > AG> [EMAIL PROTECTED]
(B>  > AG>
(B> https://lists.sourceforge.net/lists/listinfo/tapestry-developer
(B>  > 
(B>  > 
(B>  > 
(B>  > --
(B>  > with best regards
(B>  > homburg Softwaretechnik
(B>  > Sven Homburg
(B>  > Ohlendorfer Stieg 4
(B>  > 21220 Seevetal
(B>  > 
(B>  > Tel.: +49-4105-669746
(B>  > Fax.: +49-4105-668947
(B>  > http://www.: http://www.hsofttec.com
(B>  > 
(B>  > 
(B>  > 
(B>  >
(B> -------------------------------------------------------
(B>  > This sf.net email is sponsored by:ThinkGeek
(B>  > Welcome to geek heaven.
(B>  > http://thinkgeek.com/sf
(B>  > _______________________________________________
(B>  > Tapestry-developer mailing list
(B>  > [EMAIL PROTECTED]
(B>  >
(B> https://lists.sourceforge.net/lists/listinfo/tapestry-developer
(B
(B
(B
(B-------------------------------------------------------
(BThis SF.NET email is sponsored by:
(BSourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
(Bhttp://www.vasoftware.com
(B_______________________________________________
(BTapestry-developer mailing list
([EMAIL PROTECTED]
(Bhttps://lists.sourceforge.net/lists/listinfo/tapestry-developer


Reply via email to