解决tomcat服务器跨域问题

1.准备jar包

yum install -y wget vim net-tools lrzsz
rz
  • rz 上传文件

2.配置apache-tomcat-8.5.30/conf 下的web.xml

  • 配置web.xml前,先进行备份
cp web.xml web.xml.bk
<!--  跨域支持 -->
    <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> 

3.重启tomcat

  • apache-tomcat-8.5.30/bin 下
./shutdown.sh
./start.sh
  • 或者配置tomcat service
posted @ 2020-09-27 15:22  爪哇搬砖  阅读(3451)  评论(0编辑  收藏  举报