Overview Spring MVC-Dispatcher Servlet

The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files. The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features.

In Spring Web MVC you can use any object as a command or form-backing object; you do not need to implement a framework-specific interface or base class. Spring’s data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. Thus you need not duplicate your business objects’ properties as simple, untyped strings in your form objects simply to handle invalid submissions, or to convert the Strings properly. Instead, it is often preferable to bind directly to your business objects.

Spring’s view resolution is extremely flexible. A Controller is typically responsible for preparing a model Map with data and selecting a view name, but it can also write directly to the response stream and complete the request. View name resolution is highly configurable through file extension or Accept header content type negotiation, through bean names, a properties file, or even a custom ViewResolver implementation.

The model (the M in MVC) is a Map interface, which allows for the complete abstraction of the view technology. You can integrate directly with template-based rendering technologies such as JSP, Velocity and Freemarker, or directly generate XML, JSON, Atom, and many other types of content. The model Map is simply transformed into an appropriate format, such as JSP request attributes, a Velocity template model.

DispatcherServlet acts as front controller for Spring based web applications. It provides a mechanism for request processing where actual work is performed by configurable, delegate components. It is inherited from javax.servlet.http.HttpServlet, it is typically configured in the web.xml file. A web application can define any number of DispatcherServlet instances. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared. In most cases, applications have only single DispatcherServlet with the context-root URL(/), that is, all requests coming to that domain will be handled by it. DispatcherServlet uses Spring configuration classes to discover the delegate components it needs for request mapping, view resolution, exception handling etc.




Just a Mom With ADD who enjoys Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Medalla Data Challenge: TL;DR

Day 40: Secondary Power UP! Part 2!

Add Custom Marker Images for your Google Maps in Flutter

119. Pascal’s Triangle II

Infracost: The “DevFinance” Cloud Cost-Management Solution We Were Looking For

Coding Problem: Validate Subsequence in Go

THEXII NFT Collection Launch

12 effective tips to write impressive and catchy QA/Software Tester’s Resume to surely get call…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sharon Watkins

Sharon Watkins

Just a Mom With ADD who enjoys Code

More from Medium

Abstract Classes and Interfaces in Java

MapStruct for automated DTO to Entity mapping and vice versa

Signed and Unsigned Arithmetic Operators in JAVA

What is API Design First Approach — [Draft]