How can I get j_username on my index.jsp after successful authentication with j_security_check?
Asked Answered
S

1

5

I'm using j_security_check on a login.jsp. The server is GlassFish Server 3. It all works, when the user is authenticated it then opens index.jsp. My problem is I need to get j_username in my index.jsp, but I couldn't find a way of doing it. All solutions I found are in Java and I need something that works with my jsp.

Any ideas? Thank you very much in advance!

Selfappointed answered 18/2, 2011 at 15:16 Comment(0)
V
10

The involved request is in JSP EL available by PageContext#getRequest(). The logged-in user is available by HttpServletRequest#getUserPrincipal(). The username is in turn available by Principal#getName().

So,

<p>Welcome, <c:out value="${pageContext.request.userPrincipal.name}" /></p>

should do.

Using <c:out> is by the way not necessary, but useful for the case that the username could contain special HTML characters which could malform the HTML output like <, >, " and so on (which is a source for XSS attacks). The <c:out> just escapes them so that they get displayed literally instead of being interpreted as part of HTML markup.

Vitellin answered 18/2, 2011 at 19:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.