SPRINGMVC Note Series (3)--@RequestMapping request the value and method properties

Source: Internet
Author: User
Tags bind

Description: The content of this article is reproduced to: https://my.oschina.net/happyBKs/blog/411547
If there is infringement of the place, please contact me, I will be immediately deleted.

Earlier, we used the @requestmapping identity control to map the request URL to the physical view. However, this mapping of requests is not limited to the return value of the indicated method on the request URL, but it can also make a convention on the properties of the request, such as the method requested, whether it is get or post. If a conditional qualification is made for a method, a physical view cannot be generated and forwarded to the target page when the requested URL is mapped even if the method does not conform.

Here, we define a controller, as follows:

Package com.happyBKs.springmvc.handlers;

Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping ("/c3")
@Controller public
class Rmhandler {

    @RequestMapping (value= "/success", method= requestmethod.post) public
    String handle ()
    {

        return "SUCCESSRM";
    }
}

Note here that the value of the @requestmapping of the method is the original qualification of the return value. Method is the qualification of the request method property.

We create two requests on the request page, a hyperlink and a form form, they request the same URL, but one is the get method and one is the post method. We clicked and found that the GET request could not be forwarded to the target page, post can.

<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "
    pageencoding=" iso-8859-1 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Springmvc.xml, Web. XML refers to the last article.

Click the hyperlink and the result shows:

Back, click on the form request:

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.