About Question enthuware.jwpv6.2.1025 :

Moderator: admin

Post Reply
jGuriUK
Posts: 2
Joined: Sun Aug 04, 2013 10:57 pm
Contact:

About Question enthuware.jwpv6.2.1025 :

Post by jGuriUK »

I think this question's answer seems to be incorrect

If i am wrong, please correct me about below information. Thank you

setMaxInactiveInterval(-1) -- session never ends
setMaxInactiveInterval(0) -- session ends immediately
setMaxInactiveInterval(1) -- session will be invalidated after that many seconds have passed.

and as added by stella

<session-timeout>0<session-timeout> //never ends
<session-timeout>-1</session-timeout> //never ends
<session-timeout>1 </session-timeout> //time out after 1 minute

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.1025 :

Post by admin »

No, it is correct. The explanation mentions the specification section number also for this. You might want to check it out. I have no idea about stella.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

kapiteinknus
Posts: 1
Joined: Thu Aug 22, 2013 6:32 am
Contact:

Re: About Question enthuware.jwpv6.2.1025 :

Post by kapiteinknus »

I copied this from the Servlet 3.0 spec section 7.5:

This time out can be changed by the Developer using the setMaxInactiveInterval
method of the HttpSession interface. The time out periods used by these methods
are defined in seconds. By definition, if the time out period for a session is set to -1,
the session will never expire.

There is nothing in this section that says that if the time out period for a session is set to 0,
the session will never expire.

In Head First Servlets and JSP's it is said that the session is caused to time out immediately if the time out period for a session is set to 0.

So I agree with jGuriUK.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.1025 :

Post by admin »

I think I know the reason for the confusion. I looked at the most recent version of the spec ( Servlet 3.1) while responding earlier and it says in Section 7.5:
The time out periods used by these methods are defined in seconds. By definition, if the time out period for a session is set to 0 or lesser value, the session will never expire.
In Servlet 3.0, it says:
The time out periods used by these methods are defined in seconds. By definition, if the time out period for a session is set to -1, the session will never expire.
However, in JavaDoc API for HttpSession EE 6, it says:
setMaxInactiveInterval

void setMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
An interval value of zero or less indicates that the session should never timeout.

Parameters:
interval - An integer specifying the number of seconds
So, given the above details, I would say the most recent specification has only made it more clear what was
impression earlier i.e. an interval value of zero or less indicates that the session should never timeout.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

tanzwud
Posts: 19
Joined: Mon Sep 01, 2014 9:45 pm
Contact:

Re: About Question enthuware.jwpv6.2.1025 :

Post by tanzwud »

Hello again why Servlet spec 3.1 in use when exam is about Servlet spec 3.0?
setMaxInactiveInterval(0) will invalidate the session in servlet 3.0. Here is the code

Code: Select all

        PrintWriter out = resp.getWriter();
        HttpSession session = req.getSession();
        out.println("<br/> " + session.isNew());
        session.setMaxInactiveInterval(0);
        out.println("<br/> " + session.isNew());
output
IllegalStateException: isNew: Session already invalidated
Is this behaviour not guaranteed since option 4 is not valid ?
As soon as I know Servlet spec only states for dd "If the time out is 0 or less, the container ensures the default behavior of sessions is never to time out."
And no behaviour for value 0 if used with setMaxInactiveInterval "By definition, if the time out period for a session is set to -1,the session will never expire."

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.1025 :

Post by admin »

Did you go through the explanation for option 4? It explains exactly the point that you are making. Servlet 3.0 specification is not clear about what happens with time out period is set to 0. But the Servlet api version 6 (which is what the exam is also based on) says that an interval value of zero or less indicates that the session should never timeout.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests