MemeStorm

Exploring the Spring Framework and Application Development

Basic Web MVC Example - In Pictures

Posted in All by Jon on the February 12th, 2006

It seems that some of you would like a graphical depiction of what’s going on in the Basic Spring Web MVC Example. Here it is:

Webmvc-1

Here’s a summary, though I urge you to read the original blog entry and view the source for more details:

  1. A request comes in from the web cloud and your web container, Tomcat say, will examine its configuration web.xml to determine what to do with it.
  2. Here we’ve assumed that web.xml was configured to map to a dispatcher servlet (in the example, it mapped /send/* requests. There can be any number of dispatcher servlets configured.
  3. Once a dispatcher servlet receives a request, it needs to know which controller to send it to. It does this with a URL mapper. The URL mapper will typically send a request to one of many configured controllers. In our example, we mapped everything (/*) that arrives at the dispatch servlet to a single dispatchController.
  4. Incoming requests at a controller actually need to invoke a method on the controller. We’re using a MultiActionController in our example, and this uses a MethodNameResolver to determine which method to invoke. The default resolver simply takes what’s to the right of the last “/” in the incoming URL.
  5. Once the action has executed, the result has to be sent to a view. Which view, is determined by a ViewResolver. In our example, we used a InternalResourceViewResolver with a configuration such that given a view name of “foo“, will look for a JSP file “foo.jsp“.
  6. The view is rendered.

As you can tell, everything is very flexible. We can configure which dispatcher servlets are invoked when, we can configure which controller is invoked, we can configure which methods on the controller are invoked, and we can configure how the view is selected. What’s more, we can use all of the defaults to get a pretty flexible application up and running in no time.


Print This Post Print This Post

2 Responses to 'Basic Web MVC Example - In Pictures'

Subscribe to comments with RSS or TrackBack to 'Basic Web MVC Example - In Pictures'.


  1. on May 8th, 2006 at 6:52 am

    […] MemeStorm » Basic Web MVC Example – In Pictures […]


  2. on October 12th, 2006 at 1:45 am

    […] Let’s look at how to create a simple session-scoped bean that can be retrieved from the context. If you are using a DispatcherServlet (which you will be if you are using Spring’s MVC) then all you need to do is tag the bean as session-scoped in your application context configuration file. For example: […]

Leave a Reply