转自:http://stackoverflow.com/questions/2769467/what-is-dispatcher-servlet-in-spring
问:
In this image (which I got from here), HTTP request sends something to Dispatcher Servlet.
My Question is what does Dispatcher Servlet do?
Is it something like getting the information thrown from the web page and throwing it to thecontroller?
答:
The job of the DispatcherServlet is totake an incoming URI and find the right combination of handlers (generally methods on Controller classes) andviews (generally JSPs) that combine to form the page orresource that's supposed to be found at that location.
I might have
- a file
/WEB-INF/jsp/pages/Home.jsp
-
and a method on a class
@RequestMapping(value="/pages/Home.html") private ModelMap buildHome() { return somestuff; }
The Dispatcher servlet is the bit that "knows" to call that method when a browser requests the page, and tocombine its results with the matching JSP file to make an html document.
How it accomplishes this varies widely with configuration and Spring version.
There's also no reason the end result has to be web pages. It can do the same thing to locate RMIend points, handle SOAP requests, anything that can come into a servlet.
参考:
1.http://stackoverflow.com/questions/2769467/what-is-dispatcher-servlet-in-spring