Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Chapter: 28
Q441:
What does the service() method of a servlet do?
A. Handles request initialization
B. Processes client requests
C. Shuts down the servlet
D. Unloads resources
Correct Answer:
B
Chapter: 28
Q442:
When is the destroy() method called in the servlet lifecycle?
A. At initialization
B. After processing each request
C. Before servlet is unloaded
D. When the servlet is first created
Correct Answer:
C
Chapter: 28
Q443:
Which method is used to retrieve a single form parameter in a servlet?
A. getParameter()
B. getParameterValues()
C. getParameterNames()
D. getFormData()
Correct Answer:
A
Chapter: 29
Q444:
What does getParameterValues() method return?
A. A single value for a parameter
B. An array of all values for a parameter
C. A list of parameter names
D. A single parameter name
Correct Answer:
B
Chapter: 29
Q445:
If a servlet needs to handle HTTP POST requests, which method should be overridden?
A. doGet()
B. doPost()
C. init()
D. destroy()
Correct Answer:
B
Chapter: 29
Q446:
What does setting the METHOD attribute of a form to "GET" imply?
A. The request is sent as part of the URL
B. The request is hidden from the URL
C. The data is sent as part of the request body
D. The request uses the POST method
Correct Answer:
A
Chapter: 29
Q447:
What is the purpose of the <init-param> tag in web.xml?
A. Define request parameters
B. Define initialization parameters
C. Define servlet mapping
D. Define servlet class
Correct Answer:
B
Chapter: 29
Q448:
How can initialization parameters be accessed in a Servlet?
A. Using getInitParameter() method of ServletRequest
B. Using getInitParameter() method of ServletContext
C. Using getInitParameter() method of ServletConfig
D. Directly from web.xml
Correct Answer:
C
Chapter: 29
Q449:
What does the init() method in a Servlet do?
A. It initializes the Servlet
B. It handles HTTP requests
C. It reads initialization parameters
D. It sends responses
Correct Answer:
A
Chapter: 29
Q450:
In which method should you override to handle HTTP GET requests?
A. init()
B. doPost()
C. doGet()
D. processRequest()
Correct Answer:
C
Chapter: 29
Q451:
How can you redirect a response to another HTML page in a Servlet?
A. Using response.sendRedirect()
B. Using response.forward()
C. Using request.getRequestDispatcher()
D. Using response.sendError()
Correct Answer:
A
Chapter: 29
Q452:
What happens to the request object when using response.sendRedirect()?
A. The request object is preserved
B. The request object is not available
C. The request object is modified
D. The request object is merged
Correct Answer:
B
Chapter: 29
Q453:
What method can be used to forward a request to another resource within the same Servlet context?
A. sendRedirect()
B. forward()
C. include()
D. dispatch()
Correct Answer:
B
Chapter: 29
Q454:
Which class provides the getRequestDispatcher() method?
A. HttpServletResponse
B. ServletConfig
C. ServletContext
D. HttpServletRequest
Correct Answer:
C
Chapter: 29
Q455:
What is the role of RequestDispatcher.include() method?
A. To forward the request to another resource
B. To include the result of another resource in the response
C. To handle HTTP POST requests
D. To initialize Servlet parameters
Correct Answer:
B
Chapter: 29
Q456:
What is the primary purpose of the ServletContext object?
A. To manage HTTP sessions
B. To store initialization parameters for the whole application
C. To handle HTTP requests
D. To forward requests to other Servlets
Correct Answer:
B
Chapter: 29
Q457:
Which file defines the mapping of a Servlet to a URL pattern?
A. web.xml
B. web-app.xml
C. servlet-config.xml
D. app-config.xml
Correct Answer:
A
Chapter: 29
Q458:
What is the default behavior of a Servlet's doPost() method?
A. It handles HTTP GET requests
B. It processes form submissions
C. It initializes Servlet parameters
D. It handles HTTP response
Correct Answer:
B
Chapter: 30
Q459:
How does the forward() method of RequestDispatcher affect the client's view of the URL?
A. The URL changes to the new resource
B. The URL remains unchanged
C. The URL is cleared
D. The URL is updated to reflect the new resource
Correct Answer:
B
Chapter: 30
Q460:
When should you use response.sendError() method?
A. To redirect to another page with parameters
B. To send an error response with an error code and message
C. To include the result of another resource in the response
D. To forward a request to another Servlet
Correct Answer:
B