SpringMVC(十一) RequestMapping获取Cookie值


可以在控制器方法中使用类似@CookieValue("JSESSIONID") String sessionID的方式,来获取请求中的Cookie的值。

 

样例控制器代码

复制代码
package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RequestCookieTest {

@RequestMapping("testRequestCookie")
public String testCookie(@CookieValue("JSESSIONID") String sessionID){
System.out.println(sessionID);
return "success";
}
}
复制代码

 

样例视图代码:

<a href="testRequestCookie">TestRequestCookie Video11</a>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM