分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

为http请求追加cookie值

发布时间:2023-09-06 01:27责任编辑:熊小新关键词:http

1、html中引入JQuery Cookie插件。

2、JS

 ???var expiresTime = new Date(); ???expiresTime.setTime(expiresTime.getTime() + 0.5 * 60 * 1000); ???$.cookie(‘token‘, ‘曲奇饼干‘, { ???????expires : expiresTime, ?// 这里设置cookie过30分钟后失效,如果想指定天数,expiresTime改为数字即可 ???????path : ‘/‘ ???});

3、后端

 ???/** ????* 请求:测试<br> ????* 取得Http请求中的Cookie ????* ????* @author Deolin ????*/ ???@RequestMapping(value = "get_cookie", method = RequestMethod.GET) ?// 随便写个测试请求,由于path指定了/,所以任何请求中都带有了Cookie。 ???@ResponseBody ???public String get_cookie(@CookieValue(value = "token", required = false) String token) throws Exception { ???????if (token == null) { ???????????return "cookie取不到,超时或未点击“Set Cookie”。"; ???????} ???????return token; ???}

详细代码

为http请求追加cookie值

原文地址:http://www.cnblogs.com/deolin/p/7898290.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved