4 Replies Latest reply on Aug 13, 2003 3:55 PM by as280286

    Stream decoding UFT-8

    as280286

      Hello !

      I'm using jboss-3.2.1_tomcat-4.1.24. and the jvm is jdk1.3.1_02.
      I've created a JSP page made to receve a POST done by an Flash MX application (who send into the POST a XML document).

      Flash MX use an UFT-8 format to encode the xml and i would like to read correctly the stream sended. I get the XML with a function into my JSP who make a this :

      StringBuffer mXMLLine = new StringBuffer();
      String line = null;
      BufferedReader in = new BufferedReader
      ( new InputStreamReader (request.getInputStream()));

      while (null != (line = in.readLine()))
      {
      mXMLLine.append(line);
      }

      Once this is OK, y send the StringBuffer mXMLLine to an EJB who parse it well and store datas into the database correctly, excepted for accents and specials characters.

      The problem is to change the character set used into the XML stream. As it has been writed in UFT-8, i try to read the stream in UFT-8, as you can see into the code :

      BufferedReader in = new BufferedReader
      ( new InputStreamReader (request.getInputStream(),"UFT-8"));

      But i get an error :
      org.apache.jasper.JasperException: UFT-8...
      java.io.UnsupportedEncodingException: UFT-8
      at sun.io.Converters.getConverterClass(Converters.java:107) ...

      Could someone help me ?
      Thank's
      (i apologize for my very bad english ...)

        • 1. Re: Stream decoding UFT-8
          jonlee

          I'm not sure if this will solve all your issues but isn't it supposed to be UTF-8?

          • 2. Re: Stream decoding UFT-8
            as280286

            You are right.

            In fact, i think that the String included in the POST is x-www-form-urlencoded, that's why i get special characters.
            But i'm not sure, because when

            How can i retrieve my characters starting from this String ?

            • 3. Re: Stream decoding UFT-8
              jonlee

              You'll need to determine how the data is being passed. I'd have a suspicion it is being passed as a multi-part/form data and the easiest way to deal with it is to use helper classes from either Smartupload from JspSmart or from STRUTS and then work to process the uploaded "file" stream.

              Otherwise, as a name-value pair, you would just create a new string from the old one but for the UTF-8 encoding.

              This assumes that you are processing data from a POST action.

              • 4. Re: Stream decoding UFT-8
                as280286

                I've found a code who works well :

                StringBuffer mXMLLine = new StringBuffer();
                String line = null;
                String strResult ='';

                InputStreamReader insr = new InputStreamReader (request.getInputStream(),"UTF8");

                BufferedReader in = new BufferedReader(insr);

                while (null != (line = in.readLine()))
                {
                mXMLLine.append(line);
                }

                strResult = mXMLLine.toString();

                The string i get after (strResult) is well encoded (ASCII) and my accents are OK.

                I've tryed with "UFT-8" but not "UTF8"
                and the idea came from this (very well done !) link :

                http://java.sun.com/docs/books/tutorial/i18n/text/stream.html.

                If think it will be very important to know for people using FlashMX (i look at the query mode : it's a real POST).

                Thank you for your help,
                Olivier.