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!
The involved request is in JSP EL available by
PageContext#getRequest(). The logged-in user is available byHttpServletRequest#getUserPrincipal(). The username is in turn available byPrincipal#getName().So,
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.