How does the DispatcherServlet, Resolver and Controllers interact?
jsp, spring, spring-mvc
Solution
Essentially what is happening is, since you have Spring's DispatcherServlet mapped to `/*`, it tends to be called for every request(which is okay), but unfortunately gets invoked even when the request gets dispatched to the JSP page (`/WEB-INF/jsp/index.jsp`), instead of the containers default servlet getting invoked.
The fix that I am aware of is the following:
Map it to the default servlet path `/` instead:
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
One issue that you would see with above is that the resources under the root of your webapp will unfortunately get handled by DispatcherServlet which will not know what do with it, the fix is to register a default-servlet-handler this way:
<mvc:default-servlet-handler />
Problem
Ok so I have encountered the fairly common errror: `WARNING: No mapping found for HTTP request with URI [/WEB-INF/jsp/index.jsp] in DispatcherServlet with name 'app'` I'm looking at the existing answers and I've not seen a really good explanation of how the components interact. Seeing as I can't solve my issue based on the existing answers, I'm hoping someone can provide a detailed explanation of the function of `DispatcherServlet` and `Resolver`s. Developing in Eclipse, I have the following structure: ``` /src/com/whiuk/philip/web/controller/IndexController.java /WebContent /WebContent/WEB-INF /WebContent/WEB-INF/web.xml /WebContent/WEB-INF/app-servlet.xml /WebContent/WEB-INF/jsp/index.jsp ``` Eclipse Deployment Assembly means it deploys as follows: ``` /src -> WEB-INF/classes /WebContent -> / /ivy.xml[*] -> WEB-INF/lib ``` I have a web.xml file that defines a `DispatcherServlet` and a mapping to all files (`/*`) ``` <servlet> <servlet-name>app</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>app</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> ``` I have a app-servlet.xml file that scans the packages and defines a `InternalResourceViewResolver`: ``` <context:component-scan base-package="com.whiuk.philip.web" /> <mvc:annotation-driven /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> ``` I have a `IndexController` that has a RequestMapping for index: ``` @Controller public class IndexController { @RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView index() { return new ModelAndView(); } } ``` Logs show this is registered: ``` org.springframework.web.servlet.handler.AbstractHandlerMethodMapping registerHandlerMethod INFO: Mapped "{[/index],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.whiuk.philip.web.controller.IndexController.index() ``` Finally I have a index.jsp file. Can someone please explain what the misconfiguration is that results in the error shown at the top and, if possible, provide a sentence or so on the purpose of DispatcherServlet, Resolvers and how they feed into Controllers.
Related problems
- How to use a Servlet Filter to change/rewrite an incoming URL?
- Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
- Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?