Allen 专栏-移动互联网

Tomcat Ajax跨域访问

今天部署自己的solo个人博客devcoder.cn,登录时一直有提示错误信息


Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.
 
经查询是由于tomcat配置不支持ajax跨域访问,Google 搜索答案,修改tomcat 的目录下 */usr/local/tomcat/conf/web.xml/* 增加如下内容即可ok

tomcat后端允许跨域访问的配置

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
  

Read The Fucking Source
评论
validate