user1050619
user1050619

Reputation: 20906

Default Session timeout value

I'm trying to check the default value for session timeout using the below code and get the value 1800.

Question :-

  1. Here I did not create the new session object rather set the attributes value directly. Will the new session object be created automatically?

  2. I get the value of 1800..Is that in seconds or minutes. I ran this code in tomcat server.

     <% @page language = "java" %>
      <% @page isELIgnored = "false" %>
      < HTML >
      < BODY >
      < H2 > Session Update test < /H2>
        	session.setAttribute( "blah", "1234" );
        	session.setAttribute( "blah2", "1234" );
        	
        	<%
        		session.setAttribute("blah", "1234");
        		session.setAttribute("blah2", "1234");
        	%>
        	
        	<A href="updateSession.jsp">Update the Session info</A >
      < script >
      alert('Hi')
    var secondsBeforeExpire = $ {
      pageContext.session.maxInactiveInterval
    }
    var timeToDecide = 15; // Give client 15 seconds to choose.
    setInterval(function() {
      alert('MaxInactive Interval ==  ' + $ {
        pageContext.session.maxInactiveInterval
      })
    }, 1000); < /script>
        </BODY >
     < /HTML>

Upvotes: 0

Views: 2931

Answers (2)

user2575725
user2575725

Reputation:

Here I did not create the new session object rather set the attributes value directly. Will the new session object be created automatically?

By default for jsp, session is auto created, however sessions are by default created one for one user, to be specific its one browser. Yes if you use multiple browsers to access your web app, you will end up with multiple sessions. That is internally managed by the server. While you can still disabled for jsp by using this line:

<%@page session="false"%>

I get the value of 1800..Is that in seconds or minutes. I ran this code in tomcat server.

The value is in seconds.

Now apart from those questions, there are some suggestion related to your js.

var secondsBeforeExpire = ${pageContext.session.maxInactiveInterval}// its 1800
setInterval(function() {
    alert('MaxInactive Interval ==  ' + ${pageContext.session.maxInactiveInterval}) //its always 1800, not the time lapsed
}, 1000);//continuous annoying alert after every 1 second

Using setTimeout for final warning:

setTimeout(function() {
  alert('2 seconds, time"s up!');
}, 2000);
Max time out 2 seconds !

Upvotes: 1

Sethbrin
Sethbrin

Reputation: 292

For the first question: The session is created by the server once it is used.

For the second question: 1800 is in seconds equal to 30 minutes, You can config it in the web.xml file.

<session-config> 
<session-timeout>30</session-timeout> //minutes
</session-config> 

Upvotes: 1

Related Questions