为什么 HttpServletRequest 在 # 字符上截断 url 输入?
Why HttpServletRequest truncates url input on a # character?
以下 servlet 读取 url 路径参数。
问题:如果输入包含特殊字符,例如我发现 #
,那么字符串将被截断!
@RestController
public class MyServlet {
@GetMapping("/hash")
@ApiIgnore
public String hash(HttpServletRequest req) {
String pw = req.getPathInfo(); //asdfgh
}
}
`localhost:8080/hash/asdfgh#jkl`
问题:如何原生传递入参?
从 #
开始的部分不会发送 to/received 到您的 servlet。
这是仅从客户端(浏览器)使用的信息,不会
URI 的一部分。
RFC2396 确实指出:
When a URI reference is used to perform a retrieval action on the
identified resource, the optional fragment identifier, separated from
the URI by a crosshatch ("#") character, consists of additional
reference information to be interpreted by the user agent after the
retrieval action has been successfully completed. As such, it is not
part of a URI, but is often used in conjunction with a URI.
以下 servlet 读取 url 路径参数。
问题:如果输入包含特殊字符,例如我发现 #
,那么字符串将被截断!
@RestController
public class MyServlet {
@GetMapping("/hash")
@ApiIgnore
public String hash(HttpServletRequest req) {
String pw = req.getPathInfo(); //asdfgh
}
}
`localhost:8080/hash/asdfgh#jkl`
问题:如何原生传递入参?
从 #
开始的部分不会发送 to/received 到您的 servlet。
这是仅从客户端(浏览器)使用的信息,不会
URI 的一部分。
RFC2396 确实指出:
When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.