gpt4 book ai didi

java - 为什么 HttpServletRequest 会截断 # 字符上的 url 输入?

转载 作者:行者123 更新时间:2023-12-02 02:14:14 24 4
gpt4 key购买 nike

以下 servlet 读取 url 路径参数。问题:如果输入包含特殊字符,例如我发现#,那么字符串会被截断!

@RestController
public class MyServlet {
@GetMapping("/hash")
@ApiIgnore
public String hash(HttpServletRequest req) {
String pw = req.getPathInfo(); //asdfgh
}
}

`localhost:8080/hash/asdfgh#jkl`

问题:如何原生传递输入参数?

最佳答案

# 开始的部分不会发送到您的 servlet,也不会被您的 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.

关于java - 为什么 HttpServletRequest 会截断 # 字符上的 url 输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49516146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com