怎么搭建前后端跨域传递cookie环境
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这篇文章主要介绍"怎么搭建前后端跨域传递cookie环境",在日常操作中,相信很多人在怎么搭建前后端跨域传递cookie环境问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答
千家信息网最后更新 2025年12月03日怎么搭建前后端跨域传递cookie环境
这篇文章主要介绍"怎么搭建前后端跨域传递cookie环境",在日常操作中,相信很多人在怎么搭建前后端跨域传递cookie环境问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么搭建前后端跨域传递cookie环境"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
后端
新建maven项目
pom.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE com.example test-cors 0.0.1-SNAPSHOT test-cors Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
应用启动类
package com.example.testcors;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class TestCorsApplication { public static void main(String[] args) { SpringApplication.run(TestCorsApplication.class, args); }}控制器
package com.example.testcors;import org.springframework.web.bind.annotation.CookieValue;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("hello1")public class CorsController { @GetMapping("hello2") public String testController( @CookieValue(name = "testcookie") String testCookie ) { return testCookie; }}配置类
package com.example.testcors;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configurationpublic class WebMvcConfiguration implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowCredentials(true) .allowedMethods("*") .allowedOrigins("*") .allowedHeaders("*"); }}另建项目
前端
html文件
将jquery文件放入同目录下
Page Index 前台系统
本地hosts配置
添加一行
127.0.0.1 test.testcors.com
浏览器使用cookie相关插件添加cookie
域名为.testcors.com
名为 testcookie
值为任意值
到此,关于"怎么搭建前后端跨域传递cookie环境"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
环境
学习
文件
更多
项目
帮助
配置
实用
成功
接下来
一行
前台
前端
控制器
插件
文章
方法
浏览器
理论
目录
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全绿色屏障主题班会
内蒙古中小学生网络安全教育
access数据库怎么加密
网络安全公司涉及的成本
山西oa软件开发哪家专业
互联网金融概念股科技
ne安卓软件开发
网约车app软件开发成本
扬华软件开发
众神之战哪个服务器好
作为通讯作者可使用什么数据库
经营数据库
未来互联网科技股票行情
人大金仓数据库sql窗口
数据库求和怎默写语句
鸡西定制软件开发
极致零度数据库
shiro动态权限数据库
学生学习网络安全教育反响
Esemble蛋白质数据库
数据库级联查询
云端学习网络安全课后测试
服务器如何登录不了
网络安全公司涉及的成本
软件开发及运维的部门叫什么
辽宁刀片服务器云空间
行业出台网络安全管理规定
安徽视频会议服务器供应商
刺客信条关服务器
数据库查询某一列是否重复