Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Multiple Choice Questions
Q461: What should be used to store data that needs to be shared across multiple Servlets?
- A: ServletConfig
- B: ServletContext
- C: HttpSession
- D: ServletRequest
View Answer
B
Q462: What does the response.sendRedirect() method do in servlets?
- A: Forwards the request to another resource
- B: Redirects the response to another URL
- C: Includes another resource in the response
- D: Sends error response to the client
View Answer
B
Q463: What is the main difference between response.sendRedirect() and RequestDispatcher.forward()?
- A: sendRedirect() creates a new request, forward() does not
- B: sendRedirect() includes another resource, forward() does not
- C: sendRedirect() does not keep request attributes, forward() does
- D: sendRedirect() is used for error handling, forward() is not
View Answer
C
Q464: What does request.getAttribute() method return?
- A: The value of the HTTP request header
- B: The value of an attribute set by setAttribute()
- C: The URL of the request
- D: The HTTP method used for the request
View Answer
B
Q465: In which method of HttpServletRequest can you get the HTTP method used for the request?
- A: getAttribute()
- B: getMethod()
- C: getRequestURL()
- D: getProtocol()
View Answer
B
Q466: Which method is used to include the output of another resource in the response?
- A: sendRedirect()
- B: forward()
- C: include()
- D: setContentType()
View Answer
C
Q467: What is the correct way to forward a request to another servlet?
- A: request.forward("/servlet")
- B: response.sendRedirect("/servlet")
- C: request.getRequestDispatcher("/servlet").forward(request, response)
- D: request.include("/servlet")
View Answer
C
Q468: How does sendRedirect() handle request and response objects?
- A: It keeps the original request object
- B: It creates a new request object
- C: It includes the original request object
- D: It forwards the original request object
View Answer
B
Q469: Which method of HttpServletResponse is used to set the content type of the response?
- A: setContentLength()
- B: setContentType()
- C: addCookie()
- D: sendRedirect()
View Answer
B
Q470: What does the getRequestURL() method of HttpServletRequest return?
- A: The full URL of the request including query string
- B: The part of the request URL without the query string
- C: The protocol used for the request
- D: The HTTP method used for the request
View Answer
B