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
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
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
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.
4. Handler method annotation.
a) @Before
b) @Controller
c) @After
d) @RequestMapping
View Answer
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
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
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
Explanation: Map or ModelMap, for the handler method to add attributes to the model.
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
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
Explanation: SessionStatus, for the handler method to notify its completion of session processing.
10. Controller Class renders the objects passed by the controller’s handler method.
a) True
b) False
View Answer
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
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
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
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
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
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.
- Get Free Certificate of Merit in Spring
- Participate in Spring Certification Contest
- Become a Top Ranker in Spring
- Take Spring Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Spring Internship
- Buy Spring Books
- Buy Information Technology Books
- Practice Programming MCQs
- Apply for Programming Internship