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

标签 java spring servlets spring-web

以下 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/

相关文章:

Tomcat servlet 未运行 - 错误 404

java - 如何在 java 中使用 $lookup stage 和 spring data mongodb?

java - Android:SurfaceView 中 onDraw() 和 surfaceCreated() 之间的区别?

java - RecyclerView.onMeasure(...) 的空指针异常

Java3D模拟作业

java - c3p0 日志记录不起作用

spring - 基于 Restful 的视频流

javascript - 如何在javascript和servlet之间发送和接收json数据?

java - 有没有办法绕过 AuditingEntityListener 来设置测试数据?

java - 在servlet上上传 Canvas base64图像