Basic Structure and springMVC3 Learning (1) -- framework construction is similar. Annotation is not used here.
The following only describes what needs to be modified:
1. Configure HandlerMapping and HandlerAdapter in the Spring configuration file
BeanNameUrlHandlerMapping:Ing the requested URL and Bean name. For example, if the URL is "context/hello", the Spring configuration file
There must be a Bean named "/hello", and the context is ignored by default.
SimpleControllerHandlerAdapter:All beans that implement the org. springframework. web. servlet. mvc. Controller interface can be used
Spring Web MVC processor. If you need other types of processors, You can implement HadlerAdapter.
2. Modify the page ControllerLogin
Package com. itmyhome; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import org. springframework. web. servlet. modelAndView; import org. springframework. web. servlet. mvc. controller; public class Login implements Controller {public ModelAndView handleRequest (HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {return new ModelAndView ("welcome"); // return welcome. jsp page }}
Org. springframework. web. servlet. mvc. Controller: The page Controller/processor must implement the Controller Interface.
Incorrect; servlet is not a portlet
Public ModelAndView handleRequest (HttpServletRequest req, HttpServletResponse resp ):
Function processing method to implement corresponding function processing, such as collecting parameters, verifying parameters, binding parameters to command objects,
Pass the command object to the Business Object for business processing, and finally return the ModelAndView object;
ModelAndView: contains the model data and logic view name to be implemented by the view. "mv. addObject (" message "," Hello World! ");
"Indicates adding model data, which can be any POJO object;" mv. setViewName ("hello"); "indicates setting the logical view name to" hello ",
The view parser parses the view into a specific view.
3. We also need to add it to Spring configuration file springMVC. xml to accept SpringIoC container management.
Name = "/login": BeanNameUrlHandlerMapping configured on the front, which indicates that if the request URL is "context/login ",
The Bean will be handed over for processing.