Servlets Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to Servlets Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Answer : B

Explanation

Each time the server receives a request for a servlet, the server spawns a new thread and calls service() method.

Answer : C

Explanation

The POST method sends the encoded user information as a seperate message to page request. It is used to submit form data normally.

Q 3 - Which of the following code is used to get PrintWriter object in servlet?

A - response.getWriter()

B - request.getWriter()

C - new PrintWriter()

D - None of the above.

Answer : A

Explanation

You call response.getWriter() method to get PrintWriter object in servlet.

Q 4 - Which of the following code retrieves the Internet Protocol (IP) address of the client that sent the request?

A - request.getRemoteAddr()

B - response.getRemoteAddr()

C - Header.getRemoteAddr()

D - None of the above.

Answer : A

Explanation

request.getRemoteAddr() returns the Internet Protocol (IP) address of the client that sent the request.

Q 5 - Which of the following code retrieves session ID specified by the client?

A - request.getRequestedSessionId()

B - response.getRequestedSessionId()

C - Header.getRequestedSessionId()

D - None of the above.

Answer : A

Explanation

request.getRequestedSessionId() returns the session ID specified by the client.

Q 6 - Which of the following code can be used to redirect user to different url?

A - request.sendRedirect(location)

B - response.sendRedirect(location)

C - header.sendRedirect(location)

D - None of the above.

Answer : B

Explanation

response.sendRedirect(location) sends a temporary redirect response to the client using the specified redirect location URL.

Q 7 - Which of the following code can be used to set the preferred buffer size for the body of the response?

A - response.setBufferSize(size)

B - request.setBufferSize(size)

C - header.setBufferSize(size)

D - None of the above.

Answer : A

Explanation

response.setBufferSize(size) sets the preferred buffer size for the body of the response.

Q 8 - Which element of web.xml is used to specify the error handler in servlets?

A - error-page

B - error-handler

C - exception

D - exception-handler

Answer : A

Explanation

You would have to use the error-page element in web.xml to specify the invocation of servlets in response to certain exceptions or HTTP status codes.

Q 9 - Which of the following code is used to get an attribute in a HTTP Session object in servlets?

A - session.getAttribute(name)

B - session.alterAttribute(name)

C - session.updateAttribute(name)

D - None of the above.

Answer : A

Explanation

session.getAttribute() returns the object bound with the specified name in this session, or null if no object is bound under the name.

Q 10 - Which of the following code is used to set auto refresh of a page after 5 seconds?

A - session.setIntHeader("Refresh", 5)

B - response.setIntHeader("Refresh", 5)

C - request.setIntHeader("Refresh", 5)

D - None of the above.

Answer : B

Explanation

response.setIntHeader("Refresh", 5) sets refresh, autoload time as 5 seconds.


servlets-questions-answers.htm

Advertisements