Multiple choice technology security

What method is provided within the security API to prevent caching by browsers and proxies?

  1. void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response)

  2. void setNoCacheHeaders(javax.servlet.http.HttpServletRequest request)

  3. boolean setNoCacheHeader(javax.servlet.http.HttpServletResponse response)

  4. void setNoCacheHeaders(javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException

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

The correct method signature uses HttpServletResponse as the parameter since caching headers are set on the response object. The method is void because it performs an action (setting headers) rather than returning a value. Option B incorrectly uses HttpServletRequest, and options C and D have incorrect return types or exception declarations.

AI explanation

To stop sensitive pages from being cached by browsers or intermediate proxies, the utility method operates on the outgoing HttpServletResponse and sets headers like Cache-Control: no-cache, Pragma: no-cache, and Expires. It can't act on the HttpServletRequest since that represents the incoming request, not the response being sent back, and the method is a void action rather than something that returns a boolean or declares a checked exception.