我知道在SO上有许多类似的问题 – 大多数都是指用servlet过滤器实现这个概念. 我使用基于表单的声明式安全方法.并且,当一些用户在登录表单上输入他(或她)的凭证(用户名和密码)时,他
我使用基于表单的声明式安全方法.并且,当一些用户在登录表单上输入他(或她)的凭证(用户名和密码)时,他被重定向到某个/安全的jsp页面.该页面内容的一部分是:
Hello <%=request.getUserPrincipal().getName().toString()%>
You are able to view this page because you are authorized user.
现在,如果用户已登录,我想显示他/她的用户名,无论是否有安全的jsp页面.像这样的东西:
<c:if test="${statement that checks if some user is logged in}">
User: ${username of the logged user here}
</c:if>
编辑
我还想替换JSP scriptlet部分:<%= request.getUserPrincipal().getName().toString()%>使用适当的JSTL命令.
<c:if test="${not empty pageContext.request.userPrincipal}">
User: <c:out value="${pageContext.request.userPrincipal.name}" />
</c:if>
使用c:out正确地转义打印值并防止XSS攻击.
