关于Jfinal框架下跨域设置tomcat9的CORS跨域配置问题记录

博主分享了在Tomcat 9中遇到的跨域问题解决方案,强调了CORS过滤器需置于JFinal之前才能生效,并提到了清理工作和Eclipse设置对问题的影响。同时,讨论了项目中启用CORS过滤器的详细配置和排除问题的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        最近尝试设置tomcat9的CORS来进行跨域,但不论如何在tomcat的web.xml中设置都无效。最后在项目自身的web.xml中设置,一定要安排在jfinal过滤器之前,否则无法生效,并在maven中导入jar包。并由于未知原因,无法在jfinal的controller中设置log.debug()来输出信息到控制台,后恢复正常。推测是由于二种原因:1.做clean操作。2.在eclipse中设置:Project–>properties–>java compiler–>building–>configure workspace settings去掉abort build when build path errors occur前边的√。

	<filter>
		<filter-name>CORS</filter-name>
		<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
	<init-param>
		<param-name>cors.allowOrigin</param-name>
		<param-value>http://192.168.28.135:8081</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>        
         
  <filter>
    <filter-name>jfinal</filter-name>
    <filter-class>com.jfinal.core.JFinalFilter</filter-class>
    <init-param>
      <param-name>configClass</param-name>
      <param-value>com.xpgk.common.config.Config</param-value>
    </init-param>
  </filter>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值