Multiple choice technology web technology

How would you set a header named "CONTENT-LENGTH" in the HttpServletResonse object?

  1. response.setHeader(CONTENT-LENGTH,"numBytes");

  2. response.setHeader("CONTENT-LENGTH","numBytes");

  3. response.setStatus(1024);

  4. response.setHeader("CONTENT-LENGTH",1024);

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

The setHeader method in HttpServletResponse requires both parameters to be strings. Option B correctly passes the header name "CONTENT-LENGTH" and its value "numBytes" as quoted string literals. Option A is incorrect because CONTENT-LENGTH is not quoted, while D passes an integer instead of a string.