Why:MVC stands for Model‑View‑Controller, a design pattern that separates an application into three main logical components: the model, the view, and the controller.
2. What is the main role of the DispatcherServlet in Spring MVC?
Why:DispatcherServlet is the central front controller. It receives every request, finds the right controller, and coordinates the whole request‑handling process.
3. Which annotation is used to mark a class as a Controller in Spring MVC?
@...
public class MyController {
// ...
}
Why: The @Controller annotation is a specialization of @Component and is used to define a controller class.
4. What is the purpose of the @RequestMapping annotation?
Why:@RequestMapping maps web requests to specific handler methods or classes based on the URL and HTTP method.
5. What does a ViewResolver do in Spring MVC?
Why:ViewResolver takes a logical view name returned by a controller and resolves it to a concrete view (for example, a JSP file).
6. What is the default scope of a Spring MVC Controller bean?
Why: By default, a controller bean is a singleton, meaning one instance is shared across the application.
7. What is the role of the Model in Spring MVC?
Why: The Model is a container for data that the controller passes to the view for rendering.
8. Which interface represents a View in Spring MVC?
// Choose the correct interface
public interface ... {
void render(...);
}
Why: The org.springframework.web.servlet.View interface represents a view technology that can render content to the response.
9. What is the purpose of WebApplicationInitializer in Spring MVC?
Why:WebApplicationInitializer allows you to configure the ServletContext in Java code instead of using web.xml, typically to register the DispatcherServlet.
10. What is AnnotationConfigWebApplicationContext used for?
Why:AnnotationConfigWebApplicationContext is a Spring web application context that loads configuration from annotated classes, especially @Configuration classes.
11. What is the main benefit of using the MVC pattern in Spring MVC?
Why: MVC separates the application into Model, View, and Controller, which improves maintainability, testability, and organization.
12. What does the DispatcherServlet use to find the appropriate controller for a request?
Why:DispatcherServlet uses a HandlerMapping to match the request URI to a controller.
13. What does a controller method typically return in Spring MVC?
Why: A controller handler method usually returns a logical view name (a String) that the ViewResolver uses to locate the actual view.
14. What is the role of the View in the MVC pattern?
Why: The View is responsible for rendering the model data and generating the response that the client sees.
15. What is the purpose of InternalResourceViewResolver?
Why:InternalResourceViewResolver is a common ViewResolver that builds a URL by adding a prefix and suffix to the view name, typically pointing to JSP files.