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 _________ .
- A.
void log(Exception e, String s)
- B.
void destroy()
- C.
int get ServerPort()
- 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.