java webSSM解决浏览器跨域问题

1 篇文章 0 订阅
注释:
  Failed to load https://www.pole.org.cn:8443/Light_Push/webFrames.action?page=1&searchProject=1&page=1&searchProject=1: 
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin              
'https://127.0.0.1:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

可以从后台spring跨域着手解决
解决浏览器跨域问题:
第一步:导入jar包
	普通web项目:
		所需包:
		 	cors-filter-2.6.jar
			java-property-utils-1.13.jar
		下载地址:http://pan.baidu.com/s/1pLkLPGJ
	SSM项目:
		导入包:
		<dependency>
			<groupId>com.thetransactioncompany</groupId>
			<artifactId>cors-filter</artifactId>
			<version>2.6</version>
		</dependency>
		<dependency>
			<groupId>com.thetransactioncompany</groupId>
			<artifactId>java-property-utils</artifactId>
			<version>1.13</version>
		</dependency>
		Maven下载地址:http://mvnrepository.com/
		
第二步:在web.xml文件配置

	<!-- 解决浏览器跨域问题 begin -->
	<filter>
		<filter-name>CORS</filter-name>
		<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
		<init-param>
			<param-name>cors.allowOrigin</param-name>   <!--配置授信的白名单的域名! -->
			<param-value>*</param-value>
		</init-param>
		<init-param>
			<param-name>cors.supportedMethods</param-name>
			<param-value> GET, POST, HEAD, PUT, DELETE </param-value>
		</init-param>
		<init-param>
			<param-name>cors.supportedHeaders</param-name>
			<param-value> Accept, Origin, X-Requested-With, Content-Type, Last-Modified </param-value>
		</init-param>
		<init-param>
			<param-name>cors.exposedHeaders</param-name>
			<param-value>Set-Cookie</param-value>
		</init-param>
		<init-param>
			<param-name>cors.supportsCredentials</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CORS</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<!-- 解决浏览器跨域问题  end -->
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值