Java Spring Questions and Answers for freshers 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
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: Each handler interceptor must implement the HandlerInterceptor interface, which contains three callback methods for you to implement: preHandle(), postHandle(), and afterCompletion().
Java Spring for Freshers,