SCWCD : Servlet Basic Mock Exam Practice Questions
Questions no -1
Name the class that includes the getSession method that is used to get the HttpSession object?
options
A)HttpServletRequest
B)HttpServletResponse
C)SessionContext
D)SessionConfig
Correct answer is : A
Explanations : The class HttpServletRequest defines the getSession method.
Questions no -2
To send text outptut in a response, Which of the following method of HttpServletResponse
may be used to get the appropriate Writer/Stream object
options
A)getStream
B)getOutputStream
C)getBinaryStream
D)getWriter
Correct answer is : D
Explanations : 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.
Questions no -3
Which of the following statements are correct about the status of the Http response.
Select the one correct answer.
options
A)A status of 200 to 299 signifies that the request was succesful.
B)A status of 300 to 399 are informational messages.
C)A status of 400 to 499 indicates an error in the server.
D)A status of 500 to 599 indicates an error in the client
Correct answer is : A
Explanations :
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.
Questions no -4
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.
options
A)SC_OK
B)SC_MOVED_TEMPORARILY
C)SC_NOT_FOUND
D)SC_INTERNAL_SERVER_ERROR
Correct answer is : B
Explanations :
sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY (302) response code and a location header in the URL.
|