SPRINGMVC Mapping processor in the

Source: Internet
Author: User

There are three ways to handle requests to the corresponding controller in SPRINGMVC:

First, beannameurlhandlermapping (default)

The processor corresponds to the request based on the Bean's Name property

<bean class= "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> dispensable

For example:

<bean name= "/index3" class= "Com.controller.Controller1" > </bean>

Then the http://localhost:8080/spring/index3 will correspond to the Controller1, note that the name "/" must have.


Second, simpleurlhandlermapping
The processor is a simple mapping process

For example:

<bean class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name= "Mappings" >
<props>
<prop key= "/index2" >index1</prop>//index2 represents the request path, INDEX1 represents the ID of the corresponding controller
</props>
</property>
</bean>
         <bean id= "index1" class= "Com.controller.Controller1" ></bean>
then the http://localhost:8080/spring/index2 will correspond to the Controller1.
      

If our request is simply to jump to a page then you can go through:

1. <bean name= "/index" class= "Org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

When we use Http://localhost:8080/spring/index, we can jump directly to index.jsp, that is, the controller directly corresponds to the request path to a page with the same name. Here we use the default mapping processor, you can also use simpleurlhandlermapping, then the page will jump to the same name as the key page

2. <bean id= "index1" class= "Org.springframework.web.servlet.mvc.ParameterizableViewController" >
<property name= "ViewName" value= "index" ></property>
</bean>

The Simpleurlhandlermapping method is used here .





SPRINGMVC Mapping processor in the

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.