0% found this document useful (0 votes)
53 views2 pages

MVC Is An Abbreviation For A Design Pattern. What Does It Stand For and What Is The Idea Behind It? (Answer)

The document discusses key concepts in Spring MVC including: - MVC is a design pattern that separates an application into the model, view, and controller layers. The model contains the data, view renders the data, and controller handles requests and routing. - The DispatcherServlet acts as a front controller that routes requests to Spring controllers. It finds the correct controller using handler mappings and delegates the view to the ViewResolver. - The root application context loaded by the ContextLoaderListener belongs to the whole application, while individual DispatcherServlets have their own context. The ContextLoaderListener helps bootstrap Spring MVC by loading the application context.

Uploaded by

Shubham Mittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

MVC Is An Abbreviation For A Design Pattern. What Does It Stand For and What Is The Idea Behind It? (Answer)

The document discusses key concepts in Spring MVC including: - MVC is a design pattern that separates an application into the model, view, and controller layers. The model contains the data, view renders the data, and controller handles requests and routing. - The DispatcherServlet acts as a front controller that routes requests to Spring controllers. It finds the correct controller using handler mappings and delegates the view to the ViewResolver. - The root application context loaded by the ContextLoaderListener belongs to the whole application, while individual DispatcherServlets have their own context. The ContextLoaderListener helps bootstrap Spring MVC by loading the application context.

Uploaded by

Shubham Mittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. MVC is an abbreviation for a design pattern.

What does it stand for and what is


the idea behind it? (answer)
Answer - MVC is an abbreviation for Model-View-Controller design pattern. This pattern
is based upon the separation-of-concerns design principle which promotes
handling different functionality at different layer and loose coupling between layers.

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

2. Do you need spring-mvc.jar in your classpath or is it part of spring-core? (answer)


The spring-mvc.jar is not part of spring-core, which means if you want to use Spring
MVC framework in your Java project, you must include spring-mvc.jar in your
application's classpath. In Java web application, spring-mvc.jar is usually placed
inside /WEB-INF/lib folder.
3. What is the DispatcherServlet and what is it used for? (answer)
The DispatcherServlet is an implementation of Front Controller design pattern which
handles all incoming web request to a Spring MVC application. A Front
Controller pattern (see Enterprise application design pattern) is a common pattern in
web applications whose job is to receive all request and route it to different
components of application for actual processing.

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.

Technically, Spring MVC allows multiple DispatcherServlet in a Spring MVC web


application and so multiple such contexts each specific for respective servlet but
having same root context may exist
6. Here are the essential steps to enable Spring Security features in your Java web
application:
1) Declare DelegatingFilterProxy filter in web.xml
2) Specify the Spring application context file to ContextLoaderListener
3) Specify Spring Security intercept URL pattern in the applicationContext-
Security.xml file
7. Here is sample spring security Example of limiting user session in Java web
application

Read more: https://javarevisited.blogspot.com/2018/07/spring-security-concurrent-


session.html#ixzz5ZyVENEj0

<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 Max-session specifies how many concurrent authenticated session is allowed


and if error-if-maximum-exceeded set to true it will flag an error if a user tries to
login into another session.

8. What is the ContextLoaderListener and what does it do? (answer)


The ContextLoaderListener is a listener which helps to bootstrap Spring MVC. As
the name suggests it loads and create ApplicationContext, so you don't have to
write explicit code to do create it.

The application context is where Spring bean leaves. For a Web application, there is is
a subclass called WebAppliationContext.

The ContextLoaderListener also tie the lifecycle of the ApplicationContext to the


lifecycle of the ServletContext. You can get
the ServletContext from WebApplicationContext using getServletContext(
) method
9.

You might also like