Advanced Java Programming
Chapter No.6 Servlet
Assignment No.5
1. Which of the following is the default HttpRequest method? (CO6)
(a) doGet( )
(b) doPost( )
(c) doTrace( )
(d) doPut( )
2. Which life cycle method is used to process a client’s request? (CO6)
(a) start( )
(b) init( )
(c) service( )
(d) destroy( )
3. is the first Phase of Servlet Life cycle.(CO6)
(a) service( )
(b) init( )
(c) destroy( )
(d) Both B & C
4. ______ is used to read data from client request(CO6)
(a) ServletResponse
(b) ServletRequest
(c) Servlet
(d) ServletConfig
5. What is the limit of data to be passed from HTML to doGet() ? (CO6)
(a) 8kb
(b) 1kb
(c)4kb
(d)2kb
6. Apache Tomcat is . (CO6)
(a) Servlet
(b) Java Program
(c) API
(d)Web server capable of running Java programs
7. To send output in the response, the following method of HttpServlet response many be used to get the
appropriate Writer/Stream object. (CO6)
(a) getStream( )
(b) getOutputStream( )
(c) getBianaryStream( )
(d) getWriter( )
8. Can servlet class declare constructor with ServletConfig object as an argument?
a) True
b) False
9. What is the purpose of the ServletResponse object in a servlet?
a) To handle client requests
b) To obtain initialization parameters
c) To store session data
d) To send data back to the client
10. What is a servlet in Java?
a) A programming language
b) A scripting language
c) A server-side technology for Java web applications
d) A database management system
11. Which interface must a Java class implement to create a servlet?
a) Servlet
b) HttpServlet
c) ServletConfig
d) ServletRequest
12. Which HTTP method is used to retrieve data from a server using a servlet?
a) GET
b) POST
c) PUT
d) DELETE
13. Which of the following is true about servlet containers?
a) They are used to compile servlets into bytecode
b) They are responsible for managing the lifecycle of servlets
c) They are part of the Java Development Kit (JDK)
d) They are used for storing servlet-related data
14. Which method in the HttpServlet class is used to handle HTTP GET requests?
a) doGet()
b) doPost()
c) service()
d) init()
15. Which object provides information about the client's request to a servlet?
a) ServletConfig
b) HttpServletRequest
c) HttpServletResponse
d) ServletContext
16. What is the purpose of the [Link] file in a servlet-based web application?
a) To define the HTML structure of web pages
b) To configure the servlet container and servlet mappings
c) To store client-side JavaScript code
d) To define the database schema
17. Which of the following is true about servlet threading?
a) Each servlet instance runs in a separate thread
b) All servlet instances run in the same thread
c) Servlets do not support multithreading
d) Servlets always run in parallel threads
18. How can a servlet send data back to the client?
a) By calling the forward() method
b) By using the println() method of the PrintWriter class
c) By invoking the getRequestDispatcher() method
d) By setting response headers
19. Which of the following is NOT a valid method to initialize a servlet?
a) Using the init() method
b) Using the @WebServlet annotation
c) Using the [Link] deployment descriptor
d) Using the doGet() method
20. Which object is used to obtain initialization parameters in a servlet?
a) ServletConfig
b) HttpServletRequest
c) HttpServletResponse
d) ServletContext
21. What is the purpose of the doPost() method in a servlet?
a) To handle HTTP POST requests
b) To initialize the servlet
c) To handle HTTP GET requests
d) To forward the request to another resource
22. Which method is used to include the content of another resource during servlet processing?
a) include()
b) import()
c) use()
d) forward()
23. Which servlet API method is called before a servlet instance is destroyed?
a) init()
b) destroy()
c) service()
d) doGet()
24. What is the purpose of the ServletContext object?
a) To hold client session information
b) To process client requests
c) To manage the lifecycle of servlet instances
d) To provide a shared context for servlets within a web application
25. What is the purpose of the RequestDispatcher interface in a servlet?
a) To handle HTTP request headers
b) To retrieve client cookies
c) To forward or include requests to other resources
d) To manage servlet configuration settings