21.) What is the order of Servlet lifecycle methods when a Servlet is first loaded?
A) init(), service(), destroy()
B) init(), destroy(), service()
C) service(), init(), destroy()
D) service(), destroy(), init()
22.) In what scenarios might the init() method of a Servlet be called multiple times?
A) Only when the Servlet is first loaded.
B) Whenever a new client session is created.
C) Whenever a new HTTP request is received.
D) It is always called only once.
23.) What is the primary purpose of a Servlet Filter?
A) To handle HTTP requests.
B) To intercept and process requests and responses globally.
C) To generate HTML content.
D) To manage database connections.
24.) When an uncaught exception occurs in a Servlet, what is the default behavior in terms of error handling?
A) The Servlet container automatically catches and logs the exception.
B) The Servlet container sends a 500 Internal Server Error response.
C) The Servlet container redirects to a predefined error page.
D) The Servlet continues processing without any interruption.
25.) What is a session tracking mechanism used in Servlets to maintain client sessions?
A) Cookies
B) Session variables
C) URL rewriting
D) All of the above
26.) What is the primary purpose of a session cookie in a web application?
A) To store user preferences.
B) To authenticate users.
C) To identify a user’s session on the server.
D) To track user clicks on web pages.
27.) Which HTTP status code indicates a successful response in Servlets?
A) 200 OK
B) 404 Not Found
C) 500 Internal Server Error
D) 302 Found (Redirect)
28.) What is the purpose of the ServletContext object in Servlets?
A) To represent the HTTP request.
B) To store session data.
C) To provide configuration and shared resources for the entire web application.
D) To handle database connections.
29.) What is Cross-Site Scripting (XSS) in the context of web security?
A) A technique for securing Servlets.
B) A method for encrypting cookies.
C) An attack that injects malicious scripts into web pages viewed by other users.
D) A way to prevent session hijacking.
30.) When handling user input in a Servlet, what is the recommended practice to prevent SQL injection attacks?
A) Using a strong encryption algorithm.
B) Escaping user input before using it in SQL queries.
C) Storing user input in session variables.
D) Disabling user input in the Servlet.