2017-06-04 83 views
0

当我试图发送URL到服务器,它看起来像: http://192.168.0.80:8080/directory/getCertainServices/1/Кузовныеработы字符串parametern得到错误解码

但在服务器端“Кузовныеработы”参数是这样的:

ÐÑзовнÑе ÑабоÑÑ 

我使用RestTemplate从Spring框架从客户端发送的数据:

@Override 
     protected Service[] doInBackground(Object... voids) { 
      restTemplate = new RestTemplate(); 
      restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); 
      return restTemplate.getForObject(customURL, Service[].class); 
     } 

服务器端代码:

@RequestMapping(value = "/getCertainServices/{autoServiceId}/{serviceCategory}", method = RequestMethod.GET) 
    @ResponseBody 
    public List<Object> getService(@PathVariable("autoServiceId") Long autoServiceId, @PathVariable("serviceCategory") String serviceCategory){ 
     return dataBaseServiceService.findByAutoServiceAndCategory(autoServiceId, serviceCategory); 
    } 

任何人都可以给一个建议这里有什么问题吗?

更新问题: 这是否意味着我只能在URL路径中使用英文单词?

回答

1

Tomcat Wiki有一个很好的页面,名为“Character Encoding Issues”,它很好地描述了这个问题。

的解决方案取决于所使用的实际的Web服务器上,但如果它的Tomcat(默认为Spring),该解决方案是,wiki页面:

如何更改怎么弄参数解释?

Tomcat将使用ISO-8859-1作为整个URL的缺省字符编码,包括查询字符串(“GET parameters”)(尽管参见下面的Tomcat 8通知)。

有两种方法来指定参数是如何GET解释:

  • 设置元素的URIEncoding属性在server.xml中一些具体的事情(例如URIEncoding="UTF-8")。

  • 将server.xml中元素的useBodyEncodingForURI属性设置为true。这将导致连接器为GET参数使用请求主体的编码。

在Tomcat中8开始8.0.0(8.0.0-RC3,具体而言),该元件上URIEncoding属性的默认值取决于 “严格的servlet遵守” 设置。 URIEncoding的默认值(严格遵守关闭)现在是UTF-8。如果启用了“严格的servlet合规性”,则默认值为ISO-8859-1

+0

谢谢,先生! – Andrew