How can I check in an error page whether the session was timed out?
I have tried
<c:choose>
<c:when test="${empty pageContext.request.session}">
//do smth
</c:when>
<c:otherwise>
//do smth
</c:otherwise>
</c:choose>
but it doesn’t work.
There is really no reliable way to detect that. You could fiddle with some session based token as request parameter in all links/forms and validate it in the filter, but that’s fully spoofable and not really SEO friendly.
Best what you could do is to add a
<meta http-equiv="refresh">tag to the<head>of the master template which redirects the page to the session timeout error page automatically whenever the session is expired. Since you’re using a shared error page, you could pass the condition as a request parameter:and check it in the
error.jspas follows:Oh, yes,
${pageContext.session}is legitimately valid. The${pageContext.request.session}is just an unnecessary detour. Check thePageContextjavadoc for all available getters.