|
|
|
SCWD home | SCWD questions | SCWD links | SCJP home
studyjava.org - Questions on Servlets
- The method getWriter returns an object of type PrintWriter. This
class has println methods to generate output. Which of these classes
define the getWriter method? Select the one correct answer.
- HttpServletRequest
- HttpServletResponse
- ServletConfig
- ServletContext
- Name the method defined in the HttpServletResponse class that may
be used to set the content type. Do not include parenthesis after the
method.
- Which of the following statements is correct. Select the one correct
answer.
- The response from the server to a HEAD request consists of status
line, content type and the document.
- The response from the server to a GET request does not contain a
document.
- The setStatus method defined in the HttpServletRequest class takes
an int as an argument and sets the status of Http response
- The HttpServletResponse defines constants like SC_NOT_FOUND that
may be used as a parameter to setStatus method.
- The sendError method defined in the HttpServlet class is equivalent
to invoking the setStatus method with the following parameter. Select
the one correct answer.
- SC_OK
- SC_MOVED_TEMPORARILY
- SC_NOT_FOUND
- SC_INTERNAL_SERVER_ERROR
- ESC_BAD_REQUEST
- The sendRedirect method defined in the HttpServlet class is equivalent
to invoking the setStatus method with the following parameter and a
Location header in the URL. Select the one correct answer.
- SC_OK
- SC_MOVED_TEMPORARILY
- SC_NOT_FOUND
- SC_INTERNAL_SERVER_ERROR
- ESC_BAD_REQUEST
- Which of the following statements are correct about the status of
the Http response. Select the one correct answer.
- A status of 200 to 299 signifies that the request was succesful.
- A status of 300 to 399 are informational messages.
- A status of 400 to 499 indicates an error in the server.
- A status of 500 to 599 indicates an error in the client.
- To send binary outptut in a response, the following method of HttpServletResponse
may be used to get the appropriate Writer/Stream object. Select the
one correct answer.
- getStream
- getOutputStream
- getBinaryStream
- getWriter
- To send text outptut in a response, the following method of HttpServletResponse
may be used to get the appropriate Writer/Stream object. Select the
one correct answer.
- getStream
- getOutputStream
- getBinaryStream
- getWriter
- Is the following statement true or false. URL rewriting may be used
when a browser is disabled. In URL encoding the session id is included
as part of the URL.
- Name the class that includes the getSession method that is used to
get the HttpSession object.
- HttpServletRequest
- HttpServletResponse
- SessionContext
- SessionConfig
- Which of the following are correct statements. Select the two correct
answers.
- The getRequestDispatcher method of ServletContext class takes the
full path of the servlet, whereas the getRequestDispatcher method
of HttpServletRequest class takes the path of the servlet relative
to the ServletContext.
- The include method defined in the RequestDispatcher class can be
used to access one servlet from another. But it can be invoked only
if no output has been sent to the server.
- The getRequestDispatcher(String URL) is defined in both ServletContext
and HttpServletRequest method
- The getNamedDispatcher(String) defined in HttpServletRequest class
takes the name of the servlet and returns an object of RequestDispatcher
class.
Answers to questions on Servlets
- B. The class HttpServletResponse defines the getWriter method.
- setContentType
- D. The response from the server to a HEAD request does not contain the document, whereas the response to GET request does contain a document. So A and B are incorrect. C is incorrect because setStauts is defined in HttpServletResponse.
- C. sendError(String URL) is equivalent to sending SC_NOT_FOUND (404) response code.
- B. sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY (302) response code and a location header in the URL.
- A. The following table specifies the specific the status code of Http response.
| Status Code |
Purpose |
| 100-199 |
Informational |
| 200-299 |
Request was succesful |
| 300-399 |
Request file has moved. |
| 400-499 |
Client error |
| 500-599 |
Server error. |
- B. The getOutputStream method is used to get an output stream to send binary data. The getWriter method is used to get a PrintWriter object that can be used to send text data.
- D
- true. The statement about URL encoding is correct.
- A. The class HttpServletRequest defines the getSession method.
- A, C.
SCWD home | SCWD questions | SCWD links | SCJP home
|