title: java tomcat utf-8 encoding issue
body: <p>I am developing a simple web application using java/jsp/tomcat/mysql, and the most problem lies on the character encoding because I need to deal with UTF-8 encoding instead of the default 8851.</p>
  
  <p>First of I'd like to describe my program structure. I am using a Servlet called Controller.java to handle all request. So in web.xml, I have a Controller servlet which takes all request from *.do.</p>
  
  <p>Then this Controller will dispatch the request based on the requested URL, for example, if client asks for register.do, Controller will dispatch the request to Register.java.</p>
  
  <p>And in the Register.java, there is a method which takes the request as parameter, namely:</p>
  
  <pre><code>public String perform(HttpServletRequest request) {
      do something with the request...
  }
  </code></pre>
  
  <p>So the problem is if I want to print something in UTF-8 inside this method, it will give random characters. For example, I have an Enum which stores several constants, one of the properties the Enum has is its name in Traditional Chinese. If I print it in </p>
  
  <pre><code>public static void main(Stirng[] args{
      System.out.println(MyEnum.One.getChn());
      logger.info(MyEnum.One.getChn());
  }
  </code></pre>
  
  <p>This is printed correctly in Chinese. However, if I put the exact code inside the method dealing with HttpServletRequest:</p>
  
  <pre><code>public String perform(HttpServletRequest request) {
      System.out.println(MyEnum.One.getChn());
      logger.info(MyEnum.One.getChn());
  }
  </code></pre>
  
  <p>They are printed as random characters, but I can see from the debug window (eclipse) that the variables are holding correct Chinese characters.</p>
  
  <p>So, the same situation happens when I want to store the value from request.getParameter(). In the debug window, I can see the variable is holding correct characters, but one I print it out or try to store it in the database, it is random characters.</p>
  
  <p>I don't know why the behavior acts like this, and this is blocking me from reading submitted form values and store them into database. Could someone give some hints on this?</p>
  
  <p>Great thanks.</p>