Spring MVC Interview Questions Ansewrs.docx - 1 MVC is an...

  • No School
  • AA 1
  • 9

This preview shows page 1 - 3 out of 9 pages.

1. 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 Model-View-Controller design pattern. This pattern is based upon the separation-of-concerns design principle that promotes handling different functionality at different layers and loose coupling between layers. In the MVC pattern, the Model contains data that is rendered by the View and Controler help in request processing and routing. Neither Model knows about View, or that View is dependent upon Model, which means the same model can be rendered by different views, e.g. JSP or FreeMarker, or it can be even be written as JSON or XML in case of RESTful web services. The spring-mvc.jar is not part of spring-core, which means that if you want to use Spring MVC framework in your Java project, you must include spring- mvc.jar in your application's classpath. In a Java web application, spring- mvc.jar is usually placed inside the /WEB-INF/lib folder. 3. What is the DispatcherServlet and what is it used for?
Image of page 1

Subscribe to view the full document.

The DispatcherServlet is an implementation of the Front Controller design pattern that 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, the DispatcherServlet route web requests the Spring MVC controllers. In Spring MVC, DispatcherServlet is used for finding the correct Controller to process a request, which it does with the help of handler mapping, e.g. the @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? No, the DispatcherServlet is instantiated by Servlet containers like Tomcat or Jetty. You must define the 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 the 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? 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.
Image of page 2
Image of page 3
  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes