3 Replies Latest reply: May 1, 2012 6:10 AM by Jaime Poch RSS

    Incorrect chars when submitting a form

    Jaime Poch Newbie

      Hello

       

      I have a form and when I submit it, the fields containing special chars (like á,é,í,ó,ú) change to strange values.

       

      For example:

       

      á -> á

      é -> é

      í -> Ã

      ...

       

      Why?

       

      May I change the charset somewhere?

       

      Please help.

       

      Thanks

        • 1. Re: Incorrect chars when submitting a form
          valentino cruz Newbie

          Sounds like a character encoding issue.

           

          make sure you're setting the character encoding in your application. 

          are you writing to a file from java?

          If so use -Dfile.encoding=UTF-8

           

          are you writing to a database? 

          if so, there might be some properties you need to set in your connection string... for example in our MySQL connection string we had to modify the connection string to be as follows :

          jdbc:mysql://${host}${port}/${db_name}?useUnicode=true&characterEncoding=UTF-8

           

          hope that helps

          -fv

          • 2. Re: Incorrect chars when submitting a form
            Jaime Poch Newbie

            I want to persist into a database but the character changes BEFORE they are persisted to the database.

             

            I noticed this when I debug, I click the submit button and before the call to the method that make the persist, the data are already wrong.

            • 3. Re: Incorrect chars when submitting a form
              Jaime Poch Newbie

              Finally I found in the Internet a solution with a Filter and the method:

               

               

              ...

              private static String ENCODING = "UTF-8";

              ...

               

              public void doFilter(ServletRequest request, ServletResponse response,

                          FilterChain chain) throws IOException, ServletException {

                      System.out.println("CharacterEncodingFilter... doFilter");

                      request.setCharacterEncoding(ENCODING);

                      response.setCharacterEncoding(ENCODING);

                      chain.doFilter(request, response);

                  }

               

               

              But I think it should exists a more eficient way to do this!?

               

              Thank you very much