4. Get request parameters, request headers, cookies and native servlet APIs in the processing method

Source: Internet
Author: User

1. Request parameters and request headers
Using the @requestparam binding request parameter, the annotation can be passed to the request method at the entry of the processing method
--value: Name of parameter

--required: Whether it must, by default, True, indicates that the corresponding parameter must be included in the request parameter and throws an exception if it does not exist

For example:

@RequestMapping (value= "/param") public String testparam (@RequestParam (value= "name", required= true ) String name,            @RequestParam (Value= "Age", required=false, defaultvalue= "0") Integer-age) {    System.out.println ("Testparam method, name =" + Name + ", age =" + age " )            ; return SUCCESS;}

Use @requestheader to bind the request header. For example:

@RequestMapping ("/header") public String testheader (@RequestHeader (value= "Accept-language") String al) {    System.out.println ("GET request header parameter, Accept-language =" + al);             return SUCCESS;}

2. Get Cookie Value
Use @cookievalue annotations. For example:

@RequestMapping ("/testcookie") public String TestCookie (@CookieValue (value= "Jsessionid") String sessionId) {            System.out.println ("sessionId =" + sessionId);             return SUCCESS;}

3. The MVC handler method can accept parameters of the following SERVLETAPI types. These SERVLETAPI objects are passed down from the frame, and we can use them directly in the processing method. The following 9 APIs are acceptable:
1, HttpServletRequest
2, HttpServletResponse
3, HttpSession
4, Java.security.Principal
5. Locale
6, InputStream
7, OutputStream
8. Reader
9. Writer

4. Get request parameters, request headers, cookies and native servlet APIs in the processing method

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.