Yeah. I've been trying to get the ID of the currently logged in user (extracted from the session) to display on a WebManager page, using the following snippet:
<%
HttpSession session = request.getSession(true);
String userData = (String) session.getAttribute("GX_user");
if (userData != null) {
int start = userData.indexOf("<id>");
int end = userData.indexOf("</id>");
if (start != -1 && end != -1) {
String userId = userData.substring(start, end);
this.getServletContext().setAttribute("userid", userId);
}
}
%>
<c:if test="${not empty userid}">
User ID: ${userid}
<% response.getOutputStream().print(userId); %>
</c:if>
<c:if test="${empty userid}">
No user ID set, are you logged in?
</c:if>
This works, BUT, once the user ID variable has been set, it won't change into something else again (tested in this case by logging out - the page still says the current user's ID is '3'). I'm pretty sure that this is due to the caching system - i.e. a page and the replacement fields aren't regenerated for each request.
So the question is: How would I get the user ID to be regenerated and placed into the JSP's output properly each time? I've also tried the following:
response.getOutputStream().print(userId);
but that (for some reason) results in an undetailed 500 error. For the record, errors without a proper reason are irritating.
So, what's another way of doing this? I tried to look it up on Google, but I couldn't find anything, :/.