相关疑难解决方法(0)

Spring/Rest @PathVariable字符编码

在我正在使用的环境(Tomcat 6)中,路径段中的百分比序列显然在映射到@PathVariable时使用ISO-8859-1进行解码.

我希望它是UTF-8.

我已经将Tomcat配置为使用UTF-8(使用server.xml中的URIEncoding属性).

Spring/Rest是自己进行解码吗?如果是,我可以在哪里覆盖默认编码?

附加信息; 这是我的测试代码:

@RequestMapping( value = "/enc/{foo}", method = RequestMethod.GET )
public HttpEntity<String> enc( @PathVariable( "foo" ) String foo, HttpServletRequest req )
{
  String resp;

  resp = "      path variable foo: " + foo + "\n" + 
         "      req.getPathInfo(): " + req.getPathInfo() + "\n" +
         "req.getPathTranslated(): " + req.getPathTranslated() + "\n" + 
         "    req.getRequestURI(): " + req.getRequestURI() + "\n" + 
         "   req.getContextPath(): " + req.getContextPath() + "\n";

  HttpHeaders headers = new HttpHeaders();
  headers.setContentType( new MediaType( "text", …
Run Code Online (Sandbox Code Playgroud)

rest spring uri character-encoding

26
推荐指数
1
解决办法
5万
查看次数

标签 统计

character-encoding ×1

rest ×1

spring ×1

uri ×1