gpt4 book ai didi

java - Spring 的安全。授权不适用于jsp

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:25 26 4
gpt4 key购买 nike

我有以下 jsp 页面并且 jsp 按预期编译

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<c:if test="${sessionScope.userName!=null}">

...

</c:if>

在登录 Controller 方法中,我有以下行:

session.setAttribute("userName", name);

我认为最好使用 spring 安全标签重写它

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>

<sprSec:authorize access="isAuthenticated()">

...

</sprSec:authorize>

现在我尝试访问页面时出现以下错误:

  org.apache.jasper.JasperException: org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/*/*****.jsp at line 5

2: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
3: <%@ taglib prefix="sprSec" uri="http://www.springframework.org/security/tags"%>
4:
5: <sprSec:authorize access="isAuthenticated()">
6:
7: <c:set var="profileUrl" value="#" scope="request" />
8: <sprSec:authorize ifAllGranted="ROLE_USER">


....

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: java.io.IOException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags.
..........

最佳答案

这可能是 Spring Security - No visible WebSecurityExpressionHandler instance could be found in the application context 的副本.

正如那里指出的那样,确保添加 use-expressions配置的 http 属性设置为 true元素,即写 <http use-expressions="true"> .

关于java - Spring 的安全。授权不适用于jsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27344504/

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