简体   繁体   English

REST url @RequestParam编码无法解码为正确的格式(Spring MVC)

[英]REST url @RequestParam encoding cannot be decoded to proper format (Spring MVC)

I'm writing a Rest controller with Spring MVC, currently I have just one endpoint with one parameter requesting: 我正在用Spring MVC写一个Rest控制器,目前我只有一个带有一个参数请求的端点:

@RequestMapping(value = "/city", method = RequestMethod.GET)
@ResponseBody
public List<String> getCities(@RequestParam String name)  {
    ...
}

I'm working with Hungarian city names which can have some special characters (á,é,ő,ű,ú...) - they all come from the database. 我正在使用匈牙利城市名称,这些城市名称可以包含一些特殊字符(á,é,ő,ű,ú...)-它们都来自数据库。

When I call the rest endpoint with this: 当我用此调用其余端点时:

/serviceoffer/region/city?name=Borsod-Aba%C3%BAj-Zempl%C3%A9n

I get this string into the name: 我将此字符串命名为:

Borsod-Abaúj-Zemplén

but I should get this: 但我应该得到这个:

Borsod-Abaúj-Zemplén

I don't know if it's an encoding/decoding issue, but I tried to decode it without any success. 我不知道这是否是编码/解码问题,但我尝试对其进行解码,但未成功。

What could be the solution? 有什么解决方案? Many thanks! 非常感谢!

我将tomcat 7更改为tomcat 8,问题已解决...很奇怪...

Since you use Tomcat <= 7 and GET requests, you should change the URIEncoding from the default ISO8859-1 to UTF-8. 由于使用的是Tomcat <= 7GET请求,因此应将URIEncoding从默认的ISO8859-1更改为UTF-8。 Change your HTTP connector settings in config/server.xml : config/server.xml更改HTTP连接器设置:

<Connector ... URIEncoding="UTF-8" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM