我们使用的是 CAS 5.2.3,它使用了 Thymeleaf 的升级版本。 Thymeleaf 限制了对某些请求功能的访问 - '#request.getParameters()' 就是其中之一。有什么解决办法吗?我在尝试访问它时收到以下错误 - “在这种情况下禁止访问请求参数。注意一些限制适用于变量访问。例如,在预处理和未转义的表达式中,禁止直接访问请求参数,在 TEXT 模板中模式,在片段插入规范和一些特定的属性处理器中。”
最佳答案
好问题。几个月前我遇到了这个问题,它是可以解决的。
查看他们的源代码后,我发现他们限制了 #request.getParameters()
的使用。仅在特定标签上,他们并没有禁止使用 #request.getParameters()
在某种情况下。
在我的用例中,我能够使用 CData 绕过此检查。不确定它是否适用于您的用例,因为您没有提供任何代码示例....
无论如何,下面的示例希望根据参数 url
将用户重定向到另一个页面。
这是在 CAS 5.2.x 中被破坏但在 CAS 5.1.x 中工作的示例代码:
<html>
<head>
<title> Deforestation </title>
</head>
<body th:attr="onload='window.location.href=\''+${#request.getParameter('url')}+'\''">
</body>
</html>
这是一个解决代码的方法:<html>
<head>
<title> Deforestation </title>
</head>
<body>
Logging out. Please wait...
<script th:inline="javascript">
/*<![CDATA[*/
location.href = /*[[( ${#request.getParameter('url')} )]]*/ ;
/*]]>*/
</script>
</body>
</html>
如果这不能解决您的问题,请提供您的源代码,以便我们更好地查看问题。注意:现在禁止这些东西是出于安全原因,使用此解决方法可能会损害安全标准,请记住在必要时清理用户输入
编辑:
根据评论,虽然不优雅,但也许像下面这样的东西会起作用?
<html>
<head>
<title> Data attribute </title>
</head>
<body>
<span id="foobarid"> </span>
<script th:inline="javascript">
/*<![CDATA[*/
$('#foobarid').data('foo-bar',/*[[( ${#request.getParameter('foo') == 'bar'} )]]*/);
/*]]>*/
</script>
</body>
</html>
关于thymeleaf - Thymeleaf 中 #request.getParameters() 的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52592892/