Spring Questions and Answers – Spring MVC Web Applications and Requests handlers

This set of Java Spring Questions and Answers for freshers focuses on “Spring MVC Web Applications and Requests handlers”.

1. Design pattern implemented by Dispatcher Servlet.
a) jsp
b) tiles
c) front controller
d) none of the mentioned
View Answer

Answer: c
Explanation: A Spring MVC controller—often referred to as a Dispatcher Servlet—implements one of Sun’s core Java EE design patterns called front controller.

2. Class used to give a class behavior of a Dispatcher Servlet.
a) AbstractController
b) Controller
c) Abstract Class
d) AbstractAction
View Answer

Answer: a
Explanation: Prior to Spring 3.0 one of a series of classes, such as AbstractController, were used to give a class the behavior of a Dispatcher Servlet.

3. Annotation for Controller Class.
a) @Before
b) @Controller
c) @After
d) @Exception
View Answer

Answer: b
Explanation: When a @Controller annotated class (i.e., a controller class) receives a request, it looks for an appropriate handler method to handle the request.
advertisement
advertisement

4. Handler method annotation.
a) @Before
b) @Controller
c) @After
d) @RequestMapping
View Answer

Answer: d
Explanation: In order to do so, a controller class’s methods are decorated with the @RequestMapping annotation, making them handler methods.

5. Method arguments that can be used in handler methods using the @RequestMapping annotation.
a) HttpServletRequest or HttpServleResponse
b) @RequestParam
c) @ModelAttribute
d) All of the mentioned
View Answer

Answer: d
Explanation: The above mentioned is only a partial list of valid argument types, just to give you an idea.

6. Annotation which represents cookie values of requests.
a) HttpServletRequest or HttpServleResponse
b) @RequestParam
c) @Cookie
d) None of the mentioned
View Answer

Answer: d
Explanation: Cookie values included in an incoming request, annotated with @CookieValue.

7. To add attributes to the model.
a) Map
b) ModelMap
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: Map or ModelMap, for the handler method to add attributes to the model.
advertisement

8. To access the binding and validation result for the command object.
a) Errors
b) BindingResult
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: Errors or BindingResult, for the handler method to access the binding and validation result for the command object.

9. To notify its completion of session processing.
a) Errors
b) BindingResult
c) SessionStatus
d) None of the mentioned
View Answer

Answer: c
Explanation: SessionStatus, for the handler method to notify its completion of session processing.
advertisement

10. Controller Class renders the objects passed by the controller’s handler method.
a) True
b) False
View Answer

Answer: a
Explanation: Once the controller class has resolved a view name into a view implementation, per the view implementation design, it renders the objects (e.g., HttpServletRequest, Map, Errors, or SessionStatus) passed by the controller’s handler method.

11. Parameter used to specify a configuration file.
a) contextConfigLocation
b) contextConfigure
c) contextLocation
d) none of these
View Answer

Answer: a
Explanation: By default, a look is made for a file by joining the servlet name with -servlet.xml as the file name. You can explicitly specify a configuration file in the contextConfigLocation servlet parameter.

12. The @RequestMapping annotation can be applied to the class level only.
a) True
b) False
View Answer

Answer: b
Explanation: The @RequestMapping annotation can be applied to the class level or the method level.

13. Bean classes pre-registered in the web application context by default.
a) DefaultAnnotationHandlerMapping
b) AnnotationMethodHandlerAdapter
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: Next, the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter bean classes are pre-registered in the web application context by default.

14. By default, @RequestMapping gets all the POST Requests.
a) True
b) False
View Answer

Answer: b
Explanation: By default, @RequestMapping annotations assume all incoming requests are of the HTTP GET kind, which is the most common in web applications.

15. Callback methods provided by HandlerInterceptor to implement.
a) preHandle()
b) postHandle()
c) afterCompletion()
d) all of the mentioned
View Answer

Answer: d
Explanation: Each handler interceptor must implement the HandlerInterceptor interface, which contains three callback methods for you to implement: preHandle(), postHandle(), and afterCompletion().

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring for Freshers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.