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

The init method is designed to be called only once. It is called when the servlet 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 servlet.

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 any extra path information associated with the URL the client sent?

A - Header.getPathInfo()

B - response.getPathInfo()

C - request.getPathInfo()

D - None of the above.

Answer : C

Explaination

request.getPathInfo() returns any extra path information associated with the URL the client sent when it made this request.

Q 5 - Which of the following code retrieves the login of the user making this request?

A - request.getRemoteUser()

B - response.getRemoteUser()

C - Header.getRemoteUser()

D - None of the above.

Answer : A

Explaination

request.getRemoteUser() returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

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 length of content of body of the response?

A - request.setContentLength(length)

B - response.setContentLength(length)

C - header.setContentLength(length)

D - None of the above.

Answer : B

Explaination

response.setContentLength(length) sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

Answer : A

Explaination

Create cookie using new operator on Cookie class.

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

A - session.invalidate()

B - response.deleteSession()

C - request.deleteSession()

D - None of the above.

Answer : A

Explaination

session.invalidate() invalidates this session and unbinds any objects bound to it.

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

A - response.getLanguage()

B - Locale.getLanguage()

C - request.getLanguage()

D - None of the above.

Answer : C

Explaination

request.getLanguage() returns the language code in lower case for this locale in ISO 639 format.


servlets-questions-answers.htm

Advertisements