title: Spring mvc filter doesn't take effect
body: <p>I'm learning SpringMVC. The version I use is 4.2.5.RELEASE. The filter I configure in <code>web.xml</code> doesn't seem to work</p>
  
  <p><strong>Server</strong>: Tomcat 7</p>
  
  <p><strong>Problem</strong> : When I use the <code>GET</code> method to pass in Chinese parameters, even if I configure the filter for UTF-8 encoding conversion, but the string I get is still garbled </p>
  
  <p><code>web.xml</code>:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;encoding&lt;/param-name&gt;
          &lt;param-value&gt;UTF-8&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>I consider my configuration is not wrong</p>
  
  <p><code>Controller</code>:</p>
  
  <pre><code>@RequestMapping(value = "/user/info", method = RequestMethod.GET)
  public String getInfo(HttpServletRequest request,
                        @RequestParam("username") String username, Model model) {
  
      UserInfo userInfo = new UserInfo(username, "xxx", "xxx");
      Logger.i(userInfo.toString());
      model.addAttribute("info", userInfo);
      return "user/info";
  }
  </code></pre>
  
  <p>When I pass in the Chinese parameters, the information printed by the console is garbled, and it is garbled to return to the front.
  And <code>request.getCharacterEncoding()</code> return is "UTF-8"</p>
  
  <p>But when i use:</p>
  
  <pre><code>try {
      username = new String(username.getBytes("ISO-8859-1"), "UTF-8");
  } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>It can display normally.</p>
  
  <p>So I changed the default encoding of Tomcat and changed it to UTF-8. After that, even if I don't perform transcoding in the code, I can get the correct parameters.</p>
  
  <p><strong>Question</strong>: So I am very puzzled that the filter has no effect.</p>
  
  <p>I would like to express my heartfelt thanks for your enthusiasm. Thanks!</p>