This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The best way to learn about these methods is to read the API.
public boolean isNew()
Returns: true if the server has created a session, but the client has not yet joined Throws: java.lang.IllegalStateException - if this method is called on an already invalidated session
case1) The existing session(if present) no matter whatever be the value of the boolean given.
case2) If there is no existing session and boolen is true it returns a new session.
case3) If there is no existing session and boolen is false it returns null.
***coming back to case 1) Take that there is an existing session and boolean is true, does it return a new session with session context and parameters set similar to that of the incoming existing session.
Note: Iam not very sure about the last part[***coming back to case 1)].
Originally posted by Arun Kumarr: ***coming back to case 1) Take that there is an existing session and boolean is true, does it return a new session with session context and parameters set similar to that of the incoming existing session.
No. Nevertheless, it would be evil.
[Edited] BTW, how did you get this sort of thought? [ May 17, 2005: Message edited by: Adeel Ansari ]
first in "login.jsp" I have a form and on submission of the form I go to "loginServlet.java". There I get the session from the request object and add some attributes to the obtained session(say cricSession). then the control goes to "mainmenu.jsp" (i use a forward here so that the client is unaware of the changes made to session).
Now in "mainmenu.jsp", I get the session object[using "HttpSession cricSession = request.getSession(true)"] and check if it new using "cricSession.isNew()" and it says it's new.
When the server creates a session in response to the first request, the session is in a new state. So, HttpSession.isNew() will return true.
On the next request, which must include the session ID received from the server, the server will associate the request with the session. The client will then have joined the session, meaning that the session is no longer in the new state. So, HttpSession.isNew() will return false.
Chung Wee, Is sessionID created in Server or in Browser?? Like a server identifies whether a session is new, is there any way that the browser can understand about the session details( say it is new or it's an already running session)
Joined: Sep 29, 2002
When the server creates a session, it assigns it a new session ID which is sent to the client with the response. The browser stores the session ID in a cookie.
Whether the browser can make any sensible use of the information stored in the cookie I can't tell you. But as you can get a reference to HttpSession and as you know that the isNew() method returns true, then this suggests that only one session request was made. Note that isNew() would always returns true if cookies are disabled. (I am assuming that you are not using URL rewriting.)
Joined: Aug 15, 2004
Arun you need some JSP & Servlet tutorial. Try to search google. Hope you will get many.
Joined: Aug 15, 2004
Well, below is the brief explaination.
HttpSession.isNew()returns whether the session is new. A session is considered new if it has been created by the server but the client has not yet acknowledged joining the session.
For example, if a server supports only cookie-based sessions and a client has disabled the cookies, calls to request.getSession() method of always return new sessions.