I’m new to Spring, been reading a whole lot but I cannot figure out why this doesn’t work. I’ve included the relevant parts below…
web.xml:
<servlet>
<servlet-name>display</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>display</servlet-name>
<url-pattern>*.p</url-pattern>
</servlet-mapping>
display-servlet.xml:
<mvc:annotation-driven />
<context:component-scan base-package="com" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
displayController.java:
package com;
@Controller
public class displayController {
@RequestMapping("/display")
public ModelAndView displayName() {
System.out.println("-- in handleRequest");
ModelAndView mv = new ModelAndView("display");
user u = new user();
u.setUsername("bob");
mv.addObject("user", u);
return mv;
}
}
Now, as far as I know, this is what I think happens, but it isn’t..
1. I go to a url “/user/display.p”
2. Application looks in the web.xml, finds the url pattern “*.p” and notices it should be linked with the servlet display. Then an instance of DispatcherServlet is created and the context in display-servlet.xml is loaded.
3. When display-servlet.xml is loaded, it notices the mvc:annotation-driven and does something (not really sure I understand that one yet, but I think I need it. Then, it notices the component-scan and scans through the “com” package, of which displayController is located.
4. displayController is searched for annotations and it finds it is a controller, and also any url with “/display” in it should automatically trigger the displayName() function.
5. [Somewhere in here things break…]
6. Then, what SHOULD happen (but doesn’t) is the view “display” should be loaded and the “/WEB-INF/jsp/display.jsp” should be loaded. However, no view “display” is found and I receive the error “WARNING: No mapping found for HTTP request with URI [/testing/user/display.p] in DispatcherServlet with name ‘display'”
Can anyone help me on this?
Thanks!
Try this
The dispatcher will delegate requests with the pattern *.p to the dispatcherServlet and the dispatcherServlet will delegate the /user/* requests to your method.