2014-10-05 50 views
1

如何得到並顯示用戶名,用戶名,郵箱地址,ip等等,結果如下in${pageContext.request.userPrincipal}在JSP中獲取用戶詳細信息?

org.springframew[email protected]e40cde0e:校長:用戶[用戶名=管理員,[email protected],密碼= 1234,名字=奧爾加,姓氏=奧茲坎,當局= [作用[name = USER_ROLE,privileges = null]],accountNonExpired = true,accountNonLocked = true,credentialsNonExpired = true,enabled = true];證書:[PROTECTED];已驗證:true;詳細信息:org.sprin[email protected]2cd90:RemoteIpAddress:0:0:0:0:0:0:0:1; SessionId:B91578060B48D46CC606AF8281757727;授予權限:角色[name = USER_ROLE,privileges = null]

回答

3

您應該使用Spring Security JSP標記。

首先聲明的正確標籤庫:

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 

,然後使用下面的代碼來顯示例如當前用戶的電子郵件。

<sec:authentication property="principal.email" /> 

您可以用電子郵件替代主要對象(用戶名,名字等)的任何屬性。

關於Spring Security的JSP標籤的更多信息可以在文檔中找到:

http://docs.spring.io/spring-security/site/docs/3.0.x/reference/taglibs.html

相關問題