2017-03-01 56 views
0

我想顯示Authenticated user's的名字和姓氏。我將相關的代碼段放在Header.jsp中,並將其包含在另外兩個jsp頁面Index.jspNews.jsp中。<sec:授權在某些jsp頁面中不起作用

當包括在News.jspHeader.jsp,它工作正常,並顯示認證用戶的名字和姓氏,但是當它包括在Index.jsp米它不會顯示任何東西。 我的頁面結構看起來像一擊:

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> 

的index.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> 

什麼錯<sec>一點不在Index.jsp中工作?

回答

0

是否有可能Index.jsp不需要用戶進行身份驗證,但News.jsp呢?