Olete.in
Articles
Mock Tests
🧪 Servlets MCQ Quiz Hub
Servlets - Java (MCQ) questions
Choose a topic to test your knowledge and improve your Servlets skills
1. Which object of HttpSession can be used to view and manipulate information about a session?
session identifier
creation time
last accessed time
All mentioned above
2. Which class provides stream to read binary data such as image etc. from the request object?
ServltInputStream
ServletOutputStream
Both A & B
None of the above
3. Which class provides stream to read binary data such as image etc. from the request object?
ServltInputStream
ServletOutputStream
Both A & B
None of the above
4. Which of these ways used to communicate from an applet to servlet?
RMI Communication
HTTP Communication
Socket Communication
All mentioned above
5. Which methods are used to bind the objects on HttpSession instance and get the objects?
setAttribute
getAttribute
Both A & B
None of the above
6. Which type of ServletEngine is a server that includes built-in support for servlets?
Add-on ServletEngine
Embedded ServletEngine
Standalone ServletEngine
None of the above
7. What type of servlets use these methods doGet(), doPost(),doHead, doDelete(), doTrace()?
GenereiAll of the above
HttpServlets
All of the above
None of the above
8. Which cookie it is valid for single session only and it is removed each time when the user closes the browser?
Persistent cookie
Non-persistent cookie
All the above
None of the above
9. Which method is used to send the same request and response objects to another servlet in RequestDispacher ?
forward()
sendRedirect()
Both A & B
None of the above
10. Which packages represent interfaces and classes for servlet API?
javax.servlet
javax.servlet.http
Both A & B
None of the above
11. Which class can handle any type of request so that it is protocol-independent?
GenericServlet
HttpServlet
Both A & B
None of the above
12. Which HTTP Request method is non-idempotent?
GET
POST
BOTH A & B
None of the above
13. Which object is created by the web container at time of deploying the project?
ServletConfig
ServletContext
Both A & B
None of the above
14. What is the lifecycle of a servlet?
Servlet class is loaded
Servlet instance is created
init,Service,destroy method is invoked
All mentioned above
15. Which method in session tracking is used in a bit of information that is sent by a web server to a browser and which can later be read back from that browser?
HttpSession
URL rewriting
Cookies
Hidden form fields
16. In HTTP Request what asks for the loopback of the request message, for testing or for troubleshooting?
PUT
OPTIONS
DELETE
TRACE
17. In HTTP Request what asks for the loopback of the request message, for testing or for troubleshooting?
PUT
OPTIONS
DELETE
TRACE
18. In HTTP Request what asks for the loopback of the request message, for testing or for troubleshooting?
PUT
OPTIONS
DELETE
TRACE
19. In HTTP Request what asks for the loopback of the request message, for testing or for troubleshooting?
PUT
OPTIONS
DELETE
TRACE
20. Which one of the following scopes does the attribute in servlet is an object that can be set, get or removed?
session scope
request scope
application scope
All mentioned above
21. Which are the examples of Application Server?
JBoss
Weblogic
Tomcat c.
Both A & B
22. How many techniques are used in Session Tracking?
4
3
2
5
23. In the following statements identify the disadvantages of CGI?
If number of clients increases, it takes more time for sending response
For each request, it starts a process and Web server is limited to start processes
It uses platform dependent language e.g. C, C++, perl
All mentioned above
24. Which method is used to specify before any lines that uses the PintWriter?
setPageType()
. setContentType()
. setContentType()
setResponseType()
25. What are the functions of Servlet container?
Lifecycle management
Communication support
Multithreading support
All of the above
26. What are the functions of Servlet container?
Lifecycle management
Communication support
Multithreading support
All of the above
27. . What is bytecode?
Machine-specific code
Java code
Machine-independent code
None of the mentioned
28. Which of the following statements are correct about the status of the Http response.
A status of 200 to 299 signifies that the request was successful
A status of 300 to 399 are informational messages
A status of 400 to 499 indicates an error in the server
A status of 500 to 599 indicates an error in the client
29. Which JDBC driver Type(s) can be used in either applet or servlet code?
Both Type 1 and Type 2
Both Type 1 and Type 3
Both Type 3 and Type 4
Type 4 only
30. Which of the following code retrieves the MIME type of the body of the request?
new MimeType()
request.getContentType()
response.getContentType()
None of the above
31. To send text output in a response, the following method of HttpServletResponse may be used to get the appropriate Writer/Stream object.
getStreamB. . .
getOutputStream
getBinaryStream
getWriter
32. Which method take a string not a URL?
sendRedirect
forward
Both
None
33. RequestDispatcher object is used
to include other resources
to include an image
to include xml objec
to include e-mailing response
34. Which of the following are interface? 1. ServletContext 2. Servlet 3. GenericServlet 4. HttpServlet
1,2,3,4
1,2
1,3,4
1,4
35. What is the meaning of response.setHeader("xyz", "abc
Add a new header and value
Add an additional value to exiting header
Add a new header and value or add an additional value to exiting header
Add new header and value always
36. How many JDBC driver types does Sun define? One
Two.
Two
Four
Three
37. What are the features added in Servlet 2.5?
Dependency on J2SE 5.0
Support for annotations
Loading the class
All of these
38. The life cycle of a servlet is managed by
servlet context
servlet container
the supporting protocol (such as http or https)
All of the above
39. Which of the following method sets application/context init parameter?
setParameter(String name,String value
Its not possible in the method
setParameter(String name,Object value)
setParameter(Object name,Object value)
40. Which method shows the client what server is receiving?
goGet
doOption
doTrace
doPost
Submit