Spring – Shortcut to Create Dispatcher Servlet in Eclipse/Spring Tool Suite
Last Updated :
09 Jul, 2024
Eclipse is an Integrated Development Environment (IDE) used in computer programming. It includes a base workspace and an extensible plug-in system for customizing the environment. It is the second-most-popular IDE for Java development. Eclipse is written mostly in Java and its primary use is for developing Java applications, but it may also be used to develop applications in other programming languages via plug-ins, including C, C++, C#, Groovy, JavaScript, etc. Similarly, Spring Tool Suite (STS) is a java IDE tailored for developing Spring-based enterprise applications. It is easier, faster, and more convenient. And most importantly it is based on Eclipse IDE.
What is Dispatcher Servlet in Spring?
DispatcherServlet acts as the Front Controller for Spring-based web applications. So now what is Front Controller? So it is pretty simple. Any request is going to come into our website the front controller is going to stand in front and is going to accept all the requests and once the front controller accepts that request then this is the job of the front controller that it will make a decision that who is the right controller to handle that request. For example, refer to the below image. Suppose we have a website called student.com and the client is make a request to save student data by hitting the following URL student.com/save and its first come to the front controller and once the front controller accepts that request it is going to assign to the Controller_1 as this controller handle the request for /save operation. Then it is going to return back the response to the Client.

So now you might be thinking about how to create a front controller in a Spring MVC Application? But the good news is, the front controller is already created by the Spring Framework Developer, and the name of that particular controller is DispatcherServlet. You can use that front controller in your Spring MVC project. You really not required to create a front controller but you can reuse that front controller created by the Spring Framework Developer and they named it as DispatcherServlet. We can say
DispatcherServlet handles an incoming HttpRequest, delegates the request, and processes that request according to the configured HandlerAdapter interfaces that have been implemented within the Spring application along with accompanying annotations specifying handlers, controller endpoints, and response objects.
In this article What is Dispatcher Servlet in Spring? we have created our DispatcherServlet manually. But let’s take benefit of Spring Tool Suite IDE and let’s create DispatcherServlet with a shortcut method.
Step by Step Implementation:
Step 1: Create a Dynamic Web Project in your STS IDE. You may refer to this article to create a Dynamic Web Project in STS: How to Create a Dynamic Web Project in Spring Tool Suite? Make sure that you have selected Target runtime when creating the Dynamic Web Project as show in the below image.

Step 2: Right-click on the project name > New > Servlet as show in the below image.

Step 3: In the Create Servlet popup check out the “Use an existing Servlet class or JSP” box and click on the Browse button as show in the below image.

Step 4: In the next screen you have to select the Servlet and search for Dispatcher Servlet and select it and click on the OK button as show in the below image.

Note: If you are unable to find Dispatcher Servlet in your STS IDE, then
- Verify your project setup:
- Confirm you have a Dynamic Web Project
- Check if the Java EE perspective is active in STS
- Manually add Spring MVC:
- Download Spring Framework JAR files
- Add spring-webmvc-x.x.x.jar to your project’s WEB-INF/lib folder
- Update project:
- Right-click project > Properties > Java Build Path
- Add the Spring JARs to the classpath
- Clean and rebuild the project
- If still not visible, try restarting STS and refreshing the project.
Step 5: Now After selected click on the Next button. Refer to the below image if you are stuck somewhere.

Step 6: In the next screen chose your desired Dispatcher Servlet Name and also Edit your URL mappings as show in the below image. Anld click on the Finish button. You are done.

In the web.xml file you can see your Dispatcher Servlet has been created.

Tip: Below two lines are not required so you can delete them
<description></description>
<display-name>demo-frontcontroller</display-name>
And here is the complete web.xml file
Example
XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID" version="4.0">
<display-name>demo-project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>demo-frontcontroller</display-name>
<servlet-name>demo-frontcontroller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>demo-frontcontroller</servlet-name>
<url-pattern>/demo.com/*</url-pattern>
</servlet-mapping>
</web-app>
Similar Reads
Spring MVC Tutorial
In this tutorial, we'll cover the fundamentals of Spring MVC, including setting up your development environment, understanding the MVC architecture, handling requests and responses, managing forms, and integrating with databases. You'll learn how to create dynamic web pages, handle user input, and i
7 min read
Spring - MVC Framework
The Spring MVC Framework follows the Model-View-Controller architectural design pattern, which works around the Front Controller, i.e., the Dispatcher Servlet. The Dispatcher Servlet handles and dispatches all incoming HTTP requests to the appropriate controller. It uses @Controller and @RequestMapp
4 min read
Spring MVC using Java Based Configuration
Spring MVC framework enables the separation of modules, namely Model, View, and Controller, and seamlessly handles application integration. This enables the developer to create complex applications using plain Java classes. The model object can be passed between the view and the controller using map
4 min read
ViewResolver in Spring MVC
Spring MVC is a powerful Web MVC Framework for building web applications. It provides a structured way to develop web applications by separating concerns into Model, View, and Controller. One of the key features of Spring MVC is the ViewResolver, which enables you to render models in the browser wit
7 min read
How to Create Your First Model in Spring MVC?
Spring MVC is a powerful Web MVC framework for building web applications. It is designed around the Model-View-Controller (MVC) pattern, which separates the application into three main components: Model: Represents the data of the application. It can be a single object or a collection of objects.Vie
6 min read
How to Create Your First View in Spring MVC?
Spring MVC is a powerful Web MVC Framework for building web applications. It is designed around the Model-View-Controller (MVC) pattern, which separates the application into three main components: Model: Represents the data of the application. It can be a single object or a collection of objects.Vie
5 min read
Spring MVC CRUD with Example
In this article, we will explore how to build a Spring MVC CRUD application from scratch. CRUD stands for Create, Read/Retrieve, Update, and Delete. These are the four basic operations to create any type of project. Spring MVC is a popular framework for building web applications. Spring MVC follows
8 min read
Create and Run Your First Spring MVC Controller in Eclipse/Spring Tool Suite
Spring MVC framework enables the separation of modules, namely Model, View, and Controller, and seamlessly handles the application integration. This enables the developer to create complex applications also using plain Java classes. The model object can be passed between the view and the controller
5 min read
What is Dispatcher Servlet in Spring?
Spring is one of the most popular Java EE frameworks. It is an open-source lightweight framework that allows Java EE 7 developers to build simple, reliable, and scalable enterprise applications. This framework mainly focuses on providing various ways to help you manage your business objects. It made
6 min read
Spring - Shortcut to Create Dispatcher Servlet in Eclipse/Spring Tool Suite
Eclipse is an Integrated Development Environment (IDE) used in computer programming. It includes a base workspace and an extensible plug-in system for customizing the environment. It is the second-most-popular IDE for Java development. Eclipse is written mostly in Java and its primary use is for dev
4 min read