1、@CookieValue注解用于获取客户端的cookie。
2、控制器TestRequestMappingController.java
package com.springmvc.web.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping("/springmvc") public class TestRequestMappingController { @RequestMapping("/testCookieValue") public String testCookieValue( @CookieValue("JSESSIONID") String sessionIf) { System.out.println("testRequestParam, sessionIf="+sessionIf); return "success"; } }
3、访问代码
<a href="<%=path%>/springmvc/testCookieValue">Test CookieValue</a>