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