Can any one give a proper explanation for this question.
... wat will happen when a session is invalidated..
public class MyHttpSessionListener implements HttpSessionListener
public void sessionCreated (HttpSessionEvent e)
System.out.log ("Session Created");
public void sessionDestroyed (HttpSessionEvent e)
HttpSession session = e.getSession ();
String name = (String) session.getAttribute ("username");
Which of the following statements best describes the code?
� A) A compilation error will occur as the HttpSessionListener class is not properly implemented
� B) No errors or exceptions will occur as the code is written correctly
� C) An IllegalStateException will be thrown when the code is executed
� D) None of the above
The answer is given as c. and the explanation is given as
�The HttpSessionListener interface only defines the sessionCreated () and sessionDestroyed () method calls.
Hence, the code properly implements the interface correctly. So a compilation error should NOT occur.
However, at code execution, an IllegalStateException will be thrown when the session.getAttribute ("name") is called.
By the time the servlet container calls the sessionDestroyed () method, the session has already been invalidated. Therefore a call to getAttribute () will throw an IllegalStateException
but my doubt is e.getSession() will return the session tat is changed. so why cant it call the getAttribute ovet that session.
can any one help me