SpringMVC3 Learning (3) -- handlerMapping and handlerAdapter

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.