我有一些代码在我的开发机器上运行,一个普通的 mac 运行 tomcat 和
HttpServletRequest.getRequestURI()
返回完全编码的 uri。
但是在运行 apache-tomcat-7.0.32 的 Solaris 中(与我的开发机器版本相同)
我看到解码后的逗号“,”和括号“(”,“)”,而不是对返回的字符串的其余部分进行编码。换句话说,HttpServletRequest.getRequestURI()
给我一个部分编码值。
知道这是为什么吗?
最佳答案
根据规范,Web 容器不会解码 URI。 换句话说,如果 URL 已编码/未编码,它将按原样显示
String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:
First line of HTTP request Returned Value
POST /some/path.html HTTP/1.1 /some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1 /xyz
引用: http://docs.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#getRequestURI%28%29
关于java - tomcat - solaris getRequestURI() 返回部分解码的 uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713682/