首页 >> 编程问题收录 >> 当前文章

The request was rejected because the URL was not normalized

2023年10月11日 阅读量:247

问题描述:

在一次浏览网站后台日志中发现报错,org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.

报错日志:

2023-10-10 13:08:14.068 logback [http-nio-9999-exec-9] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.

问题分析:

这个错误是由Spring框架中的Spring Security组件抛出的RequestRejectedException异常。异常的原因是请求的URL没有进行规范化处理。

在Web开发中,URL规范化是指对URL进行标准化处理,确保URL符合规范和标准。通常情况下,URL需要符合RFC 3986规范,包括去除多余斜杠、处理URL编码、处理特殊字符等。

当Spring Security检测到请求的URL没有进行规范化处理时,会抛出RequestRejectedException异常,拒绝该请求的执行。

解决办法:

要解决这个错误,可以在js中用encodeURIComponent()进行编码。

// 点击搜索按钮
function clickSearch() {
    var searchKey = document.getElementById("searchKey").value
    if (searchKey) {
        // 参数用encodeURIComponent()进行编码
        window.location = "/" + pathStr + "/search?key=" + encodeURIComponent(searchKey)
    }
}
觉得有用就点个赞吧 3
称:
箱:
容:
验证码:
本站累计访客数量:13733人
本站累计运行时长:320天
声明:本站部分内容属于原创,转载请注明出处,请勿作商业用途!本站少部分资源来自互联网,如果有侵犯到您的权益,请联系本站【niceliusir@qq.com】删除,谢谢合作!