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 is used to get names of the parameters in servlet?

A - request.getParameterNames()

B - response.getParameterNames()

C - Header.getParameterNames()

D - None of the above.

Answer : A

Explaination

request.getParameterNames() returns an Enumeration of String objects containing the names of the parameters contained in this request.

Q 4 - Which of the following code retrieves name and version of the protocol?

A - Header.getProtocol()

B - response.getProtocol()

C - request.getProtocol()

D - None of the above.

Answer : C

Explaination

request.getProtocol() returns the name and version of the protocol 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

Explaination

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

Answer : B

Explaination

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

Answer : A

Explaination

The init method is designed to be called only once. It is called by the web container to indicate to a filter that it is being placed into service.

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