title: JSF Encode UTF - 8?
body: <p>Now I am working with my friend, he is Vietnamese and he wants to create a website using the Vietnamese Language, but we have a problem with Encode UTF-8.
  I wrote a Filter class as follows:</p>
  
  <pre><code>import java.io.IOException;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  public class CharsetFilter implements Filter
  {
      private String encoding;   
  
      public void init(FilterConfig config) throws ServletException
      {
          encoding = config.getInitParameter("requestEncoding");
          if( encoding==null ) encoding="UTF-8";
       }
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain  next)   throws IOException, ServletException
      {
          // Respect the client-specified character encoding
          // (see HTTP specification section 3.4.1)
          if(null == request.getCharacterEncoding())
              request.setCharacterEncoding(encoding);
          /** * Set the default response content type and encoding */
          response.setContentType("text/html; charset=UTF-8");
          response.setCharacterEncoding("UTF-8");
          next.doFilter(request, response);
          }
  
      @Override
      public void destroy() {}
  }
  </code></pre>
  
  <p>config in web.xml:</p>
  
  <pre><code>&lt;filter&gt;
          &lt;filter-name&gt;CharsetFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;com.mypackage.CharsetFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
                  &lt;param-name&gt;requestEncoding&lt;/param-name&gt;
                  &lt;param-value&gt;UTF-8&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;CharsetFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>in Server Resources - sun-resources.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd"&gt;
  &lt;resources&gt;
    &lt;jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="vietweb" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false"&gt;
          &lt;property name="serverName" value="localhost"/&gt;
          &lt;property name="portNumber" value="3306"/&gt;
          &lt;property name="databaseName" value="vietweb"/&gt;
          &lt;property name="User" value="root"/&gt;
          &lt;property name="Password" value="12345"/&gt;
           &lt;property name="useUnicode" value="true"/&gt;
          &lt;property name="characterEncoding" value="UTF8"/&gt;
          &lt;property name="URL" value="jdbc:mysql://localhost:3306/vietweb"/&gt;
          &lt;property name="driverClass" value="com.mysql.jdbc.Driver"/&gt;
    &lt;/jdbc-connection-pool&gt;
    &lt;jdbc-resource enabled="true" jndi-name="jdbc/vietweb" object-type="user" pool-name="mysql_vietweb_rootPool"/&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>in JSF page:</p>
  
  <pre><code>&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"/&gt;
  </code></pre>
  
  <p>But it is not being encoded to Vietnamese.
  How can we make it encode to Vietnamese?</p>
  
  <p>Problem with save data into DB  ( i use DB is MySQL)
  I want/expect this output:</p>
  
  <pre><code>chuyển phát nhanh để chuyển tới những cuốn sách
  </code></pre>
  
  <p>but I see this unexpected output:</p>
  
  <pre><code>chuy?n phát nhanh ?? chuy?n t?i nh?ng ??u sách 
  </code></pre>