【问题标题】:<sec:authorize does not work in some jsp pages<sec:authorize 在某些 jsp 页面中不起作用
【发布时间】:2017-07-20 20:14:33
【问题描述】:

我想显示Authenticated user's 名和姓。我把相关的代码段放在Header.jsp中,并包含在另外两个jsp页面Index.jspNews.jsp中。

Header.jsp 包含在News.jsp 中时,它可以正常工作并显示经过身份验证的用户的名字和姓氏,但是当它包含在Index.jspm 中时,它不会显示任何内容。 我的页面结构看起来很糟糕:

Header.jsp

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

       <div class="usertext">
        <span id="loginedUserFullname">
             <sec:authorize access="isAuthenticated()">
               <sec:authentication property="principal.firstname" /> 
                      <sec:authentication property="principal.lastname" />
                  <span class="welcome">welcome</span>
                  <a class="logout" href='/view/cpanel/Logout.jsp'>(loge out)</a>
                  </sec:authorize>
         </span>

 </div>
</nav>

索引.jsp

<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
    <jsp:include page="/includes/front/Header.jsp"></jsp:include>
    <jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>

News.jsp

<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<jsp:include page="/includes/front/Head.jsp"></jsp:include>
<title></title>
</head>
<body>
    <jsp:include page="/includes/front/Header.jsp"></jsp:include>
    <jsp:include page="/includes/front/Scripts.jsp"></jsp:include>
</body>

在 Index.jsp 中不起作用的 &lt;sec&gt; 有什么问题?

【问题讨论】:

    标签: java jsp spring-security


    【解决方案1】:

    是否可能 Index.jsp 不需要用户进行身份验证,但 News.jsp 需要?

    【讨论】:

      猜你喜欢
      • 2015-11-12
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2019-06-14
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多