Three methods are defined in the Handleradapter interface:
(1) Boolean supports (Object handler); Determine if the incoming handler is supported
(2) Modelandview handle (HttpServletRequest request, httpservletresponse response, Object handler) used to process requests using handler
(3) long getlastmodified (HttpServletRequest request, Object handler); The last-modified value used to obtain the data.
The interface source code is as follows:
Public interface Handleradapter {
Boolean supports (Object handler);
Modelandview handle (HttpServletRequest request, httpservletresponse response, Object handler) throws Exception;
Long getlastmodified (httpservletrequest request, Object handler);
}
The execution of the Handleradapter is performed in the Dispatcherservlet Dodispatch, and the execution process is as follows:
protected void Dodispatch (HttpServletRequest request, httpservletresponse response) throws Exception {
.....
try {
try {
//get the appropriate Handleradapter implementation class
Handleradapter ha = Gethandleradapter ( Mappedhandler.gethandler ());
........
if (Isget | | "HEAD". Equals (method)) {
Long lastmodified = ha.getlastmodified (Request, Mappedhandler.gethandler ());
}
........
Perform a true request operation
mv = Ha.handle (processedrequest, Response, Mappedhandler.gethandler ());
........
}
The gethandleradapter operation is to choose the appropriate handleradapter to execute, the adapter pattern in design mode, the content in Handleradapters is all the Handleradapter implementation class.
Protected Handleradapter Gethandleradapter (Object handler) throws Servletexception {for
(Handleradapter ha: This.handleradapters) {
if (logger.istraceenabled ()) {
Logger.trace ("Testing handler adapter [" + Ha + "]");
}
if (Ha.supports (handler)) {
return ha;
}
}
throw new Servletexception ("No Adapter for Handler [" + Handler +
"]: The Dispatcherservlet configuration needs to Inc Lude a handleradapter that supports this handler ");
}
This completes the actual invocation of the handler, and the final call procedure is to return a Modelandview object.