Multiple choice technology programming languages

You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make sure that the user continues in the same session. How do you that?

  1. 1) By calling the method with an absolute path as the argument

  2. 2) By enconding the path with HttpServletResponse.endcodeURL method

  3. 3) By enconding the path with HttpServletResponse.endcodeRedirectURL method

  4. 4) If you use sendRedirect the session is lost.

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

To maintain a session during a client-side redirect, you must encode the redirect URL using HttpServletResponse.encodeRedirectURL(String url), which appends the session ID if cookies are disabled. encodeURL is used for normal links.