Disabling session resumption on Tomcat 5.5

How to disable session timeout reset in Tomcat 5.5 for specific requests? On the page, I have a javascript function that periodically sends ajax calls to the server. On the server side, I do not want these calls to resume the session.

Thank.

+3
source share
2 answers

Well, since you didn't like my first idea, I came up with this JSP demo. This is kind of a hack, but it works. To check, copy and paste. Browse the first JSP. It will start the session and set the inactive interval. After redirecting, click the "Update" button in your browser. No matter how you request the second JSP, the current session will die.

test1.jsp

<%
   session.setMaxInactiveInterval(20); //for easy testing
   response.sendRedirect("test2.jsp");
%>

test2.jsp

<%@ page session="false" import="java.util.*" %>
<%
  HttpSession session = request.getSession(false);
  if(session == null){
                  out.print("Error, No Session!");
                  return;
  }
  long creationTime = session.getCreationTime();
  long now = new Date().getTime();
  long lastAccessedTime = session.getLastAccessedTime();
  int oldInterval = session.getMaxInactiveInterval();
  int inactivePeriod = (int)(now - lastAccessedTime)/1000; 
  session.setMaxInactiveInterval(oldInterval - inactivePeriod); 
  int newInterval = session.getMaxInactiveInterval();
%>
<html>
<body>
session id is <%=session.getId()%>
<br/><%=creationTime%> = creationTime
<br/><%=lastAccessedTime%> = lastAccessedTime
<br/><%=now%> = now
<br/><%=oldInterval%> = oldInterval in seconds 
<br/><%=inactivePeriod%> = inactivePeriod
<br/><%=newInterval%> = newInterval in seconds 
</body>
</html>
+3

- ( ), AJAX. - . , session = "false" JSP . , crossContext = "true" . Tomcat Docs

0

All Articles