The Servlet Response interface enables a servlet to formulate a response for a…

2015

The Servlet Response interface enables a servlet to formulate a response for a client using the method _________ .

  1. A.

    void log(Exception e, String s)

  2. B.

    void destroy()

  3. C.

    int get ServerPort()

  4. D.

    void set ContextType(String Type)

Attempted by 189 students.

Show answer & explanation

Correct answer: D

Correct method: setContentType(String type). This method sets the MIME type of the response so the client knows how to interpret the response body.

  • Purpose: Specify the response MIME type (for example "text/html" or "application/json").

  • Typical usage:

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    out.println("<html>...</html>");

  • Related methods: getWriter() or getOutputStream() to write the response body; setCharacterEncoding() to set charset; setStatus() to set HTTP status codes.

Explore the full course: Mppsc Assistant Professor