[MUSIC] So servlets are really helpful in building cloud base services to talk to mobile devices, but as we've seen there's still a lot of work that has to been done when a servlet receives a request. In particular, we have to do a lot of data marshalling to extract parameters from an HTP request. So we'll typically have doGet. We'll have some request object. And then in our request object we will extract information or params from the request. [BLANK_AUDIO] And then we'll do validation on those parameters. And then, we'll probably construct some java objects that use those params. [BLANK_AUDIO] And then finally we actually get to do some work. So there's a lot of overhead that goes into just processing a simple request with servlets. All of this overhead here of looking at the request, figuring out what's inside of it, figuring out if it's the same set of data that the client isn't sending anything, malicious isn't sending anything that's malformed, and there's not any other problems. We validate that data. And then finally we construct some objects. So, do some data marshalling to turn that data into some format, some object oriented format that we know how to process. And then finally we get to do work. So this is a lot of effort. So one way to handle this is a framework called the spring framework, and it provides a specialized servlet within that framewor called the dispatcher servlet that can help us to simplify a lot of this work here that we have to do over and over. Now, they're other frameworks other than the Spring Framework that do this type of work for us, but the Spring Framework is one of the most popular and widely used. So we're going to talk about it in this course. Now what the spring framework gives you is it gives us a specialized servlet called the dispatcher servlet. [BLANK_AUDIO] And what this servlet does is it allows us to register one or more controllers with this thing. So, we have one or more controllers. And again, these are just plain java objects that can handle HTP requests. But the wonderful thing about the dispatcher servlet in the spring framework, is that it allows us to stop writing all of this boilerplate code to extract parameters and do things in just right standard methods. So our controller can have simple methods like, you know, update balance. And what is called an update balance, it takes an integer for example. And whenever we send a request, the dispatcher servlet can route that request to the appropriate controller, just like we do with a web.xml file. There's a separate way of specifying routing from the dispatcher servlet to the controller. And we can do that a couple of ways, one is through an xml file, another is with some Java annotations that we'll talk about. And all of those form routing information that the dispatcher servlet can use just like the web container. So the dispatcher servlet can do a second layer of routing after the web container and what it does, is it does routing to individual methods inside of the controller. So rather than just having a single doGet method within this controller, let's say that handles get requests, we can have specific methods that have arbitrary names like update balance and then we can specify that whenever a request to a particular path or that meets some series of conditions comes in, it should be routed to this specific method. Now we have a lot more routing flexibility in the dispatcher servlet than we do in traditional you know, servlets. We can do things like look at the parameter values and do wild card matching as parameter values or path values just like we would in web.xml. And then use those to determine which individual method is invoked. So we can do an extra layer of routing in the dispatcher servlet based on not only the path of the request, but the parameters, and not just to a single servlet, but two specific methods within the servlet. So, different paths can invoke arbitrary methods within our controllers. So the dispatcher servlet gives us this extra bit of routing. But what it also does is when it, before it invokes a method, so if we map a particular request path, to this particular method. Before it invokes this method, it will automatically look at the parameters that that method requires and then look at the HTTP request and figure out if it can extract the appropriate parameters for this method call. So if for example, we have an int here, there's a way to specify that we want this integer of this method let's say, account-num parameter in the HTTP request. We can say, we want you to always map the account-num parameter in the HTTP request to this parameter to the method. And then the dispatcher servlet will automatically do all of the work to extract the parameter from the HTP request, look at it, make sure that it actually is an integer, and then pass it in and invoke this particular method. So the dispatcher servlet can do a lot of this extra work that we've previously done, from extracting parameters. The dispatcher servlet will extract them based on how we tell it to extract them and map them to the individual method parameters. It will automatically do some level of validation. And you can give it more validation to do, depending on how you configure it. But at the very least it will check that what was passed as data in the request for that particular parameter actually matches the type that you are expecting in your method. And then you can also view actual object marshalling and I'll talk more about this later but it can actually extract a series of parameters from the request. And automatically marshal them into an object that get's passed into this method. So the dispatcher servlet gives us a whole bunch of extra routing power, as well as data extraction, marshalling and validation, before we actually do work. So it's simplifies our life as developers by eliminating all of this boilerplate code that we would normally have to write.