1 Reply Latest reply on Mar 10, 2004 10:17 PM by ebdr

    character encoding problem...

    ebdr Newbie

      I have the follwing setup which works fine:

      ----------------
      search.jsp
      ----------------
      <%@ page language="java" errorPage="error.jsp" %>
      ...
      <%@ page contentType="text/html; charset=UTF-8" %>
      <%@ page pageEncoding="UTF-8"%>
      <%
      String search_string = request.getParameter("search_string");
      System.out.println("search.jsp: search_string = "+search_string);
      %>
      ...
      <html:form action="search.do" enctype="text/plain;charset=UTF-8" >
      ...
      Search:
      ...
      </html:form>
      -------------------

      but when I do the following (call my search.jsp from another jsp)
      ----------------
      preconfsearch.jsp
      ----------------
      <%@ page language="java" errorPage="error.jsp" %>
      ...
      <%@ page contentType="text/html; charset=UTF-8" %>
      <%@ page pageEncoding="UTF-8"%>
      <%
      String search_string = request.getParameter("search_string");
      System.out.println("preconfsearch.jsp: search_string = "+search_string);
      %>
      ...
      <jsp:include page="search.jsp">
      <jsp:param name="search_string" value="<%=search_string%>"/>
      </jsp:include>
      -------------------

      I have some encoding problems:
      preconfsearch.jsp: search_string = câble
      search.jsp: search_string = câble
      with:
      RESPONSE character encoding= ISO-8859-1
      REQUEST character encoding= null
      JVM encoding UTF-8

      then I tried to add a "set Encoding Filter" as follows:
      ----------------
      web.xml
      ----------------
      ...

      <filter-name>Set Character Encoding</filter-name>
      <filter-class>filters.SetCharacterEncodingFilter</filter-class>
      <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
      </init-param>

      <filter-mapping>
      <filter-name>Set Character Encoding</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      ...
      ----------------

      but then I get:
      preconfsearch.jsp: search_string = câble
      search.jsp: search_string = c?ble

      with:
      RESPONSE character encoding= ISO-8859-1
      REQUEST character encoding= UTF-8
      JVM encoding UTF-8

      why is this happening and why is my response encoding not set to UTF-8?

      thank you for your help,

      -Eric

      p.s. By the way, I am using a postgres DB with a buch of accented characters and have no problem rendering them... (my db is initialized with UTF-8 as well)

        • 1. Re: character encoding problem...
          ebdr Newbie

          I found the problem. It is a documented bug in the jsp:include tag. It does not handle encoding very well. A work around is to set the character encoding before calling jsp:include:

          request.setCharacterEncoding("UTF-8");

          -Eric

          p.s. thanks to the people who read this post!