title: How to enable reading non-ascii characters in Servlets
body: <p>How to make the servlet accept non-ascii (Arabian, chines, etc) characters passed from JSPs?</p>
  
  <p>I've tried to add the following to top of JSPs:</p>
  
  <pre><code>&lt;%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt;
  </code></pre>
  
  <p>And to add the following in each post/get method in the servlet:</p>
  
  <pre><code>request.setCharacterEncoding("UTF-8");
  response.setCharacterEncoding("UTF-8");
  </code></pre>
  
  <p>I've tried to add a Filter that executes the above two statements instead of in the servlet.</p>
  
  <p>To be quite honest, these was working in the past, but now it doesn't work anymore.</p>
  
  <p>I am using tomcat 5.0.28/6.x.x on JDK1.6 on both Win &amp; Linux boxes.</p>
  
  <p>Here's an example:
  JSP Page:</p>
  
  <pre><code>&lt;%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Push Engine&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Hello ${requestScope['val']}
  &lt;form action="ControllerServlet" method="POST"&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;ABC&lt;/td&gt;
          &lt;td&gt;&lt;input name="ABC" type="text" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="submit" value="Submit"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Servlet doGet method:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) 
              throws ServletException, IOException {
          request.setCharacterEncoding("UTF-8");
          String val = "request.getParameter('ABC') : " + request.getParameter("ABC");
          System.out.println(val);
          request.setAttribute("val", val);
          request.getRequestDispatcher("index.jsp").forward(request, response);
      }
  </code></pre>
  
  <p><strong>THE PROBLEM IS:</strong>
  in the console, value "???" is being printed, however, the value returned backed to the JSP page containing the correct Unicode word</p>
  
  <p>
  the "???" printed to the console is a problem in the machine that I ran this test on.
  I've ran the same example on another machine, and It works properly!</p>