Spring MVC编码其余URL PathVariable

时间:2015-02-27 10:18:55

标签: ajax spring rest http spring-mvc

我想删除此元数据:“déééé”

我有这个HTTP REQUEST:

DELETE /test/api/metadata/d%C3%A9%C3%A9%C3%A9%C3%A9 HTTP/1.1
Host: localhost:8585
Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: http://localhost:8585
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Referer: http://localhost:8585/test/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=4f789...

我有这个映射控制器:

  @RequestMapping(value = "metadata/{categoryName}", produces = "application/json", method = DELETE)
  public @ResponseBody boolean deleteMetadata(@PathVariable String categoryName) { 
      return test.deleteCategory(categoryName);
  }

但是在我的控制器中,我得到了这样的结果:dé©é©错误编码

在我的web.xml中我有这个:

<filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

什么是缺少

1 个答案:

答案 0 :(得分:1)

URL的编码由服务器定义。如果您使用Tomcat然后在server.xml中的某个位置设置了连接器。只需添加首选编码:

<Connector port="8080" URIEncoding="UTF-8" />