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 : C

Explaination

A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.

Q 2 - What is javax.servlet.http.HttpServlet?

A - interface

B - abstract class

C - concreate class

D - None of the above.

Answer : B

Explaination

javax.servlet.http.HttpServlet is an abstract class.

Q 3 - Which of the following code retrieves the name of the authentication scheme?

A - new AuthType()

B - response.getAuthType()

C - request.getAuthType()

D - None of the above.

Answer : C

Explaination

request.getAuthType() returns the name of the authentication scheme used to protect the servlet, for example, BASIC or SSL or null if the JSP was not protected.

Q 4 - Which of the following code retrieves the character encoding used in the body of this request?

A - new CharacterEncoding()

B - response.getCharacterEncoding()

C - request.getCharacterEncoding()

D - None of the above.

Answer : C

Explaination

request.getCharacterEncoding() returns the name of the character encoding used in the body of this request.

Q 5 - Which of the following code returns the port number on which this request was received?

A - response.getServerPort()

B - request.getServerPort()

C - Header.getServerPort()

D - None of the above.

Answer : B

Explaination

request.getServerPort() returns the port number on which this request was received.

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 character encoding for the body of the response?

A - response.setCharacterEncoding(charset)

B - request.setCharacterEncoding(charset)

C - header.setCharacterEncoding(charset)

D - None of the above.

Answer : A

Explaination

response.setCharacterEncoding(charset) sets the character encodinge for the body of the response.

Answer : C

Explaination

The init method is designed to be called only once. It is called when the filter is first created, and not called again for each user request. It simply creates or loads some data that will be used throughout the life of the filter.

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

A - session.addAttribute(name,value)

B - session.setAttribute(name,value)

C - session.createAttribute(name,value)

D - None of the above.

Answer : B

Explaination

session.setAttribute() binds an object to this session, using the name specified.

Q 10 - Which of the following code is used to get locale in servlets?

A - request.getLocale()

B - Locale.getLocale()

C - response.getLocale()

D - None of the above.

Answer : A

Explaination

request.getLocale() returns Local object.

servlets-questions-answers.htm
Advertisements