Fixed several dispatch servlets in web.xml

September 03, 2020 by Leslie Edison

 

You can see an error message that says there are multiple dispatcher servlets in the web.xml. There are two different ways to solve this problem, and this is what we will explain now.

This Windows 7 DVD Creator supports the common video, audio and audio file formats listed below.
  • Supported video formats: ASF, AVI, DVR-MS, M1V, MP2, MP2V, MPE, MPEG, MPG, MPV2, WM, WMV.
  • Supported image formats: BMP, DIB, EMF, GIF, JFIF, JPE, JPEG, JPG, PNG, TIF, TIFF, WMF.

 

 



If you're familiar with Spring, you know where the DispatcherServlet fits into this framework because it handles the rendering of views in Spring MVC and files. I recently had a game with this framework along with several others, and there I ran into an issue in Spring MVC when I was completing several sections in a given project. I wanted to set up mapping for different sections separately so that when accessing a file from http: // localhost: 8080 / module1 / index.html, completely different sections appear in the module1 servlet XML which is stored in the Web Deployer web.xml is defined as -



And then I try to create a DispatcherServlet for another section - Module2 - with the same signature as Module1 in web.xml -


multiple dispatcher servlet in web.xml

In this configuration, when trying to open http: // localhost: 8080 / module2 / index.html, a 404 error is displayed, which means that page not found . If you've worked on the Struts framework, you may already be familiar with the workaround.


Why do we need multiple dispatcher servlet in spring?

DispatcherServlet acts as a front controller for Spring based web applications. It provides a mechanism for handling requests, where the real work is done by custom delegate components. It is inherited from Javax.


This is because we are using the same > tag for both modules with the same servlet class - DispatcherServlet - which is not correct. We can have several DispatcherServlets with different tag values ​​ . To fix this, I changed the entry for module2 in web.xml to -


How does dispatcher servlet know which controller calls?

1 answer. Since the mapping notes are static and never change at runtime, there is no need to parse each controller class to find the appropriate method when processing a request. Just scan it once when you start the application and save the scan result to a card.