@CookieValue綁定請求中的cookie
阿新 • • 發佈:2018-02-06
user alt ext string span head ans sessionid 請求頭
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.效果
@CookieValue綁定請求中的cookie