Multiple choice technology programming languages

Given the definition of MyServlet: public class MyServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); session.setAttribute("myAttribute","myAttributeValue"); session.invalidate(); response.getWriter().println("value=" + session.getAttribute("myAttribute")); } } What is the result when a request is sent to MyServlet?

  1. An IllegalStateException is thrown at runtime.

  2. An InvalidSessionException is thrown at runtime.

  3. The string "value=null" appears in the response stream.

  4. The string "value=myAttributeValue" appears in the response stream.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Calling session.invalidate() immediately invalidates the session. Any subsequent attempt to call session.getAttribute() or perform operations on that invalidated session object will throw an IllegalStateException at runtime.