Multiple choice technology programming languages

You want to use URL rewriting to support client browsers, which do not use cookies. Which method will you use to attach the session id to a URL that is to be used for the sendRedirect() method of the HttpServletResponse?

  1. encodeURL

  2. encodeRedirectURL

  3. encodeSessionURL

  4. encodeSessionRedirectURL

  5. None of these

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

For sendRedirect(), you must use encodeRedirectURL(). The encodeURL() method is for regular URLs (links in HTML, form actions). encodeRedirectURL() specifically handles the session encoding rules required for redirect responses.

AI explanation

To attach the session ID to a URL that is to be used for the sendRedirect() method of the HttpServletResponse, you can use the encodeRedirectURL method.

The correct answer is B) encodeRedirectURL.

Explanation for each option:

A) encodeURL - This method is used to encode the URL, including the session ID, if necessary. However, when using the sendRedirect() method, encodeRedirectURL should be used instead.

B) encodeRedirectURL - This method is used to encode the URL, including the session ID, if necessary, specifically for the sendRedirect() method.

C) encodeSessionURL - This method does not exist in the HttpServletResponse class.

D) encodeSessionRedirectURL - This method does not exist in the HttpServletResponse class.

E) None of these - The correct answer is B) encodeRedirectURL.

Therefore, the correct answer is B) encodeRedirectURL.