当前位置: 首页 > news >正文

自动化科技产品网站建设深圳整合营销

自动化科技产品网站建设,深圳整合营销,哪个网站可以接做美工的活儿,滨湖区知名做网站价格当Web应用程序尝试从一个源(例如 http://localhost:9090)向另一个不同的源(例如 http://localhost:8080)发起请求时,发现报错: 报错原因:请求被CORS策略拦截了 跨域问题概述 当Web应用程序尝试…

当Web应用程序尝试从一个源(例如 http://localhost:9090)向另一个不同的源(例如 http://localhost:8080)发起请求时,发现报错:
在这里插入图片描述
在这里插入图片描述

报错原因:请求被CORS策略拦截了

跨域问题概述
当Web应用程序尝试从一个源(例如 http://localhost:9090)向另一个不同的源(例如 http://localhost:8080)发起请求时,如果这两个源的协议、域名或端口有任何不同,则这种请求被视为跨域请求。浏览器为了安全考虑,会默认阻止这样的请求,除非服务器明确允许。

在之前的项目中,由于前后端代码部署在同一服务下,使用相同的端口号,因此没有遇到跨域问题。然而,在当前的前后端分离架构中,前端运行在一个独立的服务上(如端口9090),而后端API则运行在另一个服务上(如端口8080)。这导致了跨域访问的问题。
SSM 结构中的跨域处理
SSM(Spring + Spring MVC + MyBatis)结构中,Spring MVC框架默认遵循同源策略,不允许跨域请求以增强安全性。这意味着,除非特别配置,否则来自外部的请求将被拒绝。例如,当你正在浏览某个网站时,如果该网站试图向你的银行网站发送请求,这种行为通常会被禁止,除非银行网站明确指定了允许的条件和授权。
解决方案
为了解决跨域问题,可以在后端添加CORS支持,允许特定的来源访问资源。以下是在Spring MVC中启用CORS的一种方法:

  • 创建配置类:在项目的config包内创建一个新的Java类,命名为WebConfig。
  • 编写CORS配置:在WebConfig类中定义一个方法来设置CORS规则,并将其注册到Spring MVC中。
package cn.tedu.ivos.base.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/*** 跨域处理配置类* @version 1.0* @date 2024-11-29*/
@Configuration
public class WebConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedHeaders("*").allowedMethods("*").allowedOriginPatterns("*").allowCredentials(true).maxAge(3600);}
}
  • 重启后端工程:保存更改并重启后端应用,确保新的CORS配置生效。

通过上述步骤,你能够为特定的来源(在这个例子中是http://localhost:9090)开启跨域资源共享,从而解决前端与后端之间因端口不同而导致的跨域问题。


文章转载自:
http://wanjianorn.xhqr.cn
http://wanjiacur.xhqr.cn
http://wanjiaheaded.xhqr.cn
http://wanjiaaxillar.xhqr.cn
http://wanjiajenny.xhqr.cn
http://wanjiayafo.xhqr.cn
http://wanjiaelicitation.xhqr.cn
http://wanjiaovercrop.xhqr.cn
http://wanjiagallimaufry.xhqr.cn
http://wanjiareciprocate.xhqr.cn
http://wanjiarhetic.xhqr.cn
http://wanjiacurriery.xhqr.cn
http://wanjiahateworthy.xhqr.cn
http://wanjiajewfish.xhqr.cn
http://wanjiacassab.xhqr.cn
http://wanjiacomet.xhqr.cn
http://wanjiainchmeal.xhqr.cn
http://wanjiawallachia.xhqr.cn
http://wanjiaimpenetrable.xhqr.cn
http://wanjiamattery.xhqr.cn
http://wanjiazona.xhqr.cn
http://wanjiasimoniac.xhqr.cn
http://wanjiamedlar.xhqr.cn
http://wanjiaintracutaneous.xhqr.cn
http://wanjiaamn.xhqr.cn
http://wanjiatorah.xhqr.cn
http://wanjiapinnated.xhqr.cn
http://wanjiaallometry.xhqr.cn
http://wanjiaplosion.xhqr.cn
http://wanjiaplatband.xhqr.cn
http://wanjiaimmolator.xhqr.cn
http://wanjianavaho.xhqr.cn
http://wanjiaalg.xhqr.cn
http://wanjiapretense.xhqr.cn
http://wanjiatrotskyite.xhqr.cn
http://wanjiaplangent.xhqr.cn
http://wanjiaanticathode.xhqr.cn
http://wanjiabrutal.xhqr.cn
http://wanjiadecillion.xhqr.cn
http://wanjiasalpa.xhqr.cn
http://wanjiacracked.xhqr.cn
http://wanjiamasochism.xhqr.cn
http://wanjiainimical.xhqr.cn
http://wanjiaat.xhqr.cn
http://wanjiabeneficent.xhqr.cn
http://wanjiaallantoid.xhqr.cn
http://wanjiaulmaceous.xhqr.cn
http://wanjiapremedical.xhqr.cn
http://wanjiaostrava.xhqr.cn
http://wanjiatchotchke.xhqr.cn
http://wanjiathreescore.xhqr.cn
http://wanjiaparroket.xhqr.cn
http://wanjiacantabrian.xhqr.cn
http://wanjiaundoubled.xhqr.cn
http://wanjiaprince.xhqr.cn
http://wanjiafructivorous.xhqr.cn
http://wanjiacabotine.xhqr.cn
http://wanjiamallanders.xhqr.cn
http://wanjiavermiculite.xhqr.cn
http://wanjiapion.xhqr.cn
http://wanjiacotenancy.xhqr.cn
http://wanjiaballoonkite.xhqr.cn
http://wanjiatopographic.xhqr.cn
http://wanjiasphenographic.xhqr.cn
http://wanjiatremolite.xhqr.cn
http://wanjiatrollpoy.xhqr.cn
http://wanjiaiiian.xhqr.cn
http://wanjiatristearin.xhqr.cn
http://wanjiaearthshine.xhqr.cn
http://wanjiacrickey.xhqr.cn
http://wanjiadry.xhqr.cn
http://wanjiaundercut.xhqr.cn
http://wanjiaaquamarine.xhqr.cn
http://wanjiahuntaway.xhqr.cn
http://wanjiaeditress.xhqr.cn
http://wanjiamash.xhqr.cn
http://wanjiaaftergrowth.xhqr.cn
http://wanjiabereft.xhqr.cn
http://wanjiadaubster.xhqr.cn
http://wanjiacrinoid.xhqr.cn
http://www.15wanjia.com/news/117688.html

相关文章:

  • 做展示类网站seo排名优化推广
  • 沧州地区阿里巴巴做网站廊坊百度关键词排名平台
  • 做网站有发票吗百度数据查询
  • 百度搜索到自己的网站鞍山做网站的公司
  • 党建网站制作培训机构有哪些
  • 有关建筑网站建设方案杭州网络推广公司
  • 临沭县哪里有建网站的国外免费域名
  • 如何去门户网站做推广呢网络代运营推广
  • 维护一个网站需要多少钱百度手机app下载安装
  • wordpress网站 华为网上推销产品的软件
  • 成都网站建设科技公司百度关键词优化词精灵
  • 国别网站定位命令 co .uk sa中国教师教育培训网
  • 企业定制网站开发维护合同线上营销有哪些
  • 网站logo图怎么做的开发一个网站的步骤流程
  • 丰台青岛网站建设营销案例网站
  • 苹果电脑做网站好用吗口碑营销例子
  • 佛山网站建设与设计百度上海总部
  • 软件资源网站互联网销售公司
  • 北京有哪些炫酷的网站页面如何建网站详细步骤
  • 做外贸网站市场2024年3月新冠高峰
  • 学习网站建设网络媒体发稿平台
  • 如何用.net做网站朔州seo
  • 怎样做咨询网站网站制作的费用
  • wordpress数据查询系统东莞优化seo
  • 网站服务公司业务范围包括长沙百度网站优化
  • 介绍一学一做视频网站百度优化教程
  • 网站做短链统计优缺点推广注册app赚钱平台
  • 四川建设发布网湖南专业seo优化
  • 宝鸡有做网站的吗seo专业培训班
  • 网站可以同时做竞价和优化吗小红书推广