MCQ Bank
To redirect to an HTML page named index.html located at the root of the web application, what should be the argument to sendRedirect()?
- A) sendRedirect("webapp/index.html")
- B) sendRedirect("index.html")
- C) sendRedirect("contextPath/index.html")
- D) sendRedirect("WEB-INF/index.html")
How do you set the maximum age of a Cookie object in Java?
- A) myCookie.setMaxAgeInSeconds(3600);
- B) myCookie.setAge(3600);
- C) myCookie.setExpiration(3600);
- D) myCookie.setMaxAge(3600);
What is a package in Java?
- A) A group of classes with similar functionality.
- B) A folder or directory that organizes related classes and interfaces.
- C) A collection of methods for a specific task.
- D) A set of variables used in a program.
Which of the following is responsible for handling user interactions and displaying data in a Java application?
- A) Persistence layer
- B) Business layer
- C) Presentation layer
- D) Data layer
getProtocol() method of HTTPServletRequest is used to get the _________ and ___________ of protocol.
- A) id, version
- B) id, class
- C) name, version
- D) name, class
In which technique does the server store a unique session identifier on the client's browser?
- A) Cookies
- B) Hidden form fields
- C) Database storage
- D) URL rewriting
Which of the following is not the stage of servlet lifecycle?
- A) Service
- B) Initialize
- C) Wait
- D) Destroy
JSP directives can be used to affect which part of the web application?
- A) The client-side JavaScript
- B) The overall structure of the servlet
- C) Only the database connection
- D) Only the HTML content
Server spawns a new thread for each new request from the client by calling servlet's ________________ method.
- A) yield()
- B) init()
- C) service()
- D) spwan()
A servlet _____________ during its initialize stage.
- A) forwards request/s
- B) loads resource/s
- C) unloads resource/s
- D) accepts request/s
Context attributes are shared among _____________ servlet/s of ___________ .
- A) two, a web application
- B) all, a web application
- C) all, desktop applications
- D) two, desktop applications
The data layer in Java applications is responsible for:
- A) Handling user input validation and error handling
- B) Storing and retrieving data from persistent storage
- C) Handling user authentication and authorization
- D) Presenting data to the user in a user-friendly format
The __________________ method actually processes the clients request.
- A) yield()
- B) init()
- C) service()
- D) destroy()
Resources could be shared among all servlets in _______________ application/s using _____________ .
- A) different, Servlet object
- B) same, ServletContext object
- C) different, ServletContext object
- D) same, Servlet object
How does URL rewriting work in Java web applications?
- A) Replacing URL paths with user-friendly aliases.
- B) Appending session ID as a query parameter to the URL.
- C) Storing session ID in cookies.
- D) Modifying the URL in the client's browser using JavaScript.
Which of the following object is used for sharing resources among different servlets of same application?
- A) ServletRequest
- B) ServletContext
- C) ServletResponse
- D) ServletConfig
What is session tracking in web applications?
- A) Monitoring server performance
- B) Recording user demographics
- C) Maintaining stateful information about user interactions
- D) Tracking user location on the website
Which of the following is the correct format of writing a taglib directive in JSP?
- A) <%$ taglib {attribute=”val”} %>
- B) <%# taglib {attribute=”val”} %>
- C) <%! taglib {attribute=”val”} %>
- D) <%@ taglib {attribute=”val”} %>
setContentLength() method of HTTPServletResponse sets the length of content by taking _____________ parameter as length.
- A) character
- B) float
- C) string
- D) integer
What is a cookie in the context of web browsing?
- A) A type of browser plugin
- B) A security feature for preventing malware
- C) A small piece of data stored on the user's device by websites
- D) A small piece of cake served by websites