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

Q 1 - Which of the following package contains servlet classes?

A - javax.servlet

B - javax.servlet.http

C - Both of the above.

D - None of the above.

Answer : C

Explaination

Servlets can be created using the javax.servlet and javax.servlet.http packages, which are a standard part of the Java's enterprise edition, an expanded version of the Java class library that supports large-scale development projects.

Answer : C

Explaination

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 retrieves the body of the request as binary data?

A - new InputStream()

B - response.getInputStream()

C - request.getInputStream()

D - None of the above.

Answer : C

Explaination

request.getInputStream() retrieves the body of the request as binary data using a ServletInputStream.

Q 4 - Which of the following code retrieves the query string that is contained in the request URL after the path?

A - Header.getQueryString()

B - response.getQueryString()

C - request.getQueryString()

D - None of the above.

Answer : C

Explaination

request.getQueryString() returns the query string that is contained in the request URL after the path.

Q 5 - Which of the following code indicates whether the response has been committed?

A - response.isCommitted()

B - request.isCommitted()

C - Header.isCommitted()

D - None of the above.

Answer : A

Explaination

response.isCommitted() returns a boolean indicating if the response has been committed.

Answer : A

Explaination

response.addDateHeader(name,date) adds a response header with the given name and date-value.

Q 7 - Which of the following code can be used to set the status code of the response?

A - response.setStatus(statusCode)

B - request..setStatus(statusCode)

C - header..setStatus(statusCode)

D - None of the above.

Answer : A

Explaination

response.setLocale(locale) sets the status code of the response.

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

A - session.getSessionId()

B - session.getId()

C - session.getActiveId()

D - None of the above.

Answer : B

Explaination

session.getId() returns a string containing the unique identifier assigned to this session.

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

Explaination

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

servlets-questions-answers.htm
Advertisements