Search code examples
jspscriptlet

How to call ${SPRING_SECURITY_LAST_EXCEPTION.message} in a jsp scriptlet?


I have to remove jstl library (license issues). What is the correct way to re-write <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> using a jsp scriptlet?

I tried the below code among several others:

<%= session.getAttribute("SPRING_SECURITY_LAST_EXCEPTION.message") %>

but it returns null.

Also, I cannot simply change to ${SPRING_SECURITY_LAST_EXCEPTION.message} because all special html characters need to be escaped.


Solution

  • SPRING_SECURITY_LAST_EXCEPTION is a session attribute in which a spring exception has been stored so you must access it as following:

    <%= session.getAttribute("SPRING_SECURITY_LAST_EXCEPTION").getMessage() %>
    

    SPRING_SECURITY_LAST_EXCEPTION represents an exception and message is one of its properties.

    EDIT:

    <%= ((AuthenticationCredentialsNotFoundException)session.getAttr‌​ibute("SPRING_SECURI‌​TY_LAST_EXCEPTION"))‌​.getMessage() %> worked. Of course, I had to import AuthenticationCredentialsNotFoundException