MVC Is An Abbreviation For A Design Pattern. What Does It Stand For and What Is The Idea Behind It? (Answer)
MVC Is An Abbreviation For A Design Pattern. What Does It Stand For and What Is The Idea Behind It? (Answer)
In MVC pattern, Model contains the data which is rendered by View and Controler help
in request processing and routing.
Neither Model knows about View, nor View is dependent upon Model, which means the
same model can be rendered by different views e.g. JSP, FreeMarker or it can be even
be written as JSON or XML in case of RESTful Web Services
In case of Spring MVC, DispatcherServlet route web requests to Spring MVC controllers.
In Spring MVC, DispatcherServlet is used for finding the correct Controler to process
a request, which it does with the help of handler mapping
e.g. @RequestMapping annotation.
It is also responsible for delegating logical view name to ViewResolver and then
sending the rendered response to the client.
4. Is the DispatcherServlet instantiated via an application context? (answer)
No, DispatcherServlet is instantiated by Servlet containers like Tomcat or Jetty.
You must define DispatcherServlet into the web.xml file as shown below.
You can see that load-on-startup tag is 1 which means DispatcherServlet is instantiated
when you deploy Spring MVC application to Tomcat or any other Servlet container.
During instantiation, it looks for a file servlet-name-context.xml and then initializes
beans defined in this file.
5. What is the root application context in Spring MVC? How is it loaded? (answer)
In Spring MVC, the context loaded using ContextLoaderListener is called the
"root" application context which belongs to the whole application while the one
initialized using DispatcherServlet is actually specific to that servlet.
<session-management invalid-session-url="/logout.html">
<concurrency-control max-sessions="1" error-if-maximum-
exceeded="true" />
</session-management>
As you see you can specify how many concurrent session per user is
allowed, a most secure system like online banking portals allows just one authenticated
session per user.
The application context is where Spring bean leaves. For a Web application, there is is
a subclass called WebAppliationContext.