007 @CookieValue绑定请求中的cookie

1.介绍

  

2.使用的cookie

  

3.index.jsp

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 
11     测试cookie
12     <br>
13     <a href="helloworld5/">JSESSIONID</a>
14     <br><br>
15     
16     测试请求头
17     <br>
18     <a href="helloworld4/">Accept-Language</a>
19     <br><br>
20     
21     测试请求参数
22     <br>
23     <a href="helloworld3?username=cj&age=13">Test Rest Get</a>
24     <br>
25 </body>
26 </html>

4.controller

 1 package com.spring.it;
 2 
 3 import org.springframework.stereotype.Controller;
 4 import org.springframework.web.bind.annotation.CookieValue;
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 
 7 @Controller
 8 public class RequestParamControl {
 9     @RequestMapping("/helloworld5")
10     public String hello(@CookieValue(value="JSESSIONID") String sessionId) 
11     {
12         System.out.println("JSESSIONID="+sessionId);
13         return "success";
14     }
15 }

5.效果

  

原文地址:https://www.cnblogs.com/juncaoit/p/8419745.html