This Article is not completely accurate.  The following is true and comes
from an e-mail conversation with Hans Bergsten who wrote the Java Server
Pages Book:

The Servlet spec before the new 2.3 uses ISO-8859 as the default encoding
and de-coding for the servlet container.  How you encode your web pages
determines how the browser interprets and encodes GET/POST values.  If you
have a page with a form encoded in UTF-8 and submit it using a java
application server or java web server whose servlet container version is
lower than 2.3, your submitted values WILL BE DE-CODED by default using
ISO-8859 regardless.  You can do/try 1 of 2 things. 1) If your app server
allows, like weblogic, you can declare the inputCharset value in the web xml
file inside your WEB-INF directory. 2) You can do what the article below
mentioned and get the bytes of the parameter each time, and make a new
String using the encoding you want.  Ex.

     private String getEncodedCharacters(String originalContent){
          String utf8String = null;
          try{
               byte[] bytes = originalContent.getBytes("8859_1");//THIS IS A
NECESSARY STEP UNTIL SERVLET SPEC 2.3
               utf8String =  new String(bytes, encoding);
          }catch(UnsupportedEncodingException uee){
               System.out.println("Exception in handleCharacters method: " +
"\n" + uee.getMessage());
          }
          return utf8String;
     }





----- Original Message -----
From: "Turgay Zengin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 17, 2001 6:01 AM
Subject: Re: National characters don't reach Action class correctly


> Hi!
> Yes, that really helps, thank you.
> I also found the same thing at a message in java-apache-users archive at
> http://www.geocrawler.com/archives/3/440/2000/2/0/3373820
>
> The interesting thing is, this doesn't happen if the Struts <html:form>
tag
> is used - then I get the correct characters. I am trying to figure out
why,
> digging in code for org/apache/struts/taglib/html/FormTag.java
>
> Thanks again,
> Turgay Zengin.
> -----------------------------
>
> Peiqiang Han wrote:
> >Turgay,
>
> >If you use Tomcat 4.0 (servlet spec 2.3), you can just wirte:
>
> >request.setCharacterEncoding("ISO-8895-9");
> >System.out.println(request.getParameter("filename"));
>
> >If you use Tomcat 3.2 (Servlet spec 2.2),
>
> >String data = request.getParameter("filename");
> >byte[] raw = data.getBytes("ISO-8859-1");
> >System.out.println(new String(raw, "ISO-8859-9"));
>
> >hope this helps,
> >Peiqiang Han
>
> Turgay Zengin wrote:
>
> >Hi,
> >I need help on this:
> >Problem is, I can see national characters on jsp pages correctly, but
when
> >I
> >post data to an Action, the string gets messed up. I couldn't find
related
> >info in the archive.
> ....
> ....
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>

Reply via email to