No & #39; Access

Source: Internet
Author: User
A Java Web project CrossDomainTest using OpenLayers is deployed in eclipse. The container is Tomcat 7.0.56. (localhost: container) and Geoserver2.5.2. the built-in container jetty6.18 is used to publish the WFS service. (localhost: 8888 geoserverwfs). From localh

A Java web project CrossDomainTest using OpenLayers is deployed in eclipse, and the container is Tomcat 7.0.56. (http: // localhost: 8080/CrossDomainTest/index.html) Use Geoserver 2.5.2 to use the built-in container jetty 6.18 to publish the WFS service. (http: // localhost: 8888/geoserver/wfs ). from localh

A Java web project CrossDomainTest using OpenLayers is deployed in eclipse, and the container is Tomcat 7.0.56. (http: // localhost: 8080/CrossDomainTest/index.html)

Use Geoserver 2.5.2 to use the built-in container jetty 6.18 to publish the WFS service. (http: // localhost: 8888/geoserver/wfs ).

WFS accessing localhost: 8080 from localhost: 8888 cannot achieve the expected results. An error is found through chrome browser developer tools: no 'access-Control-Allow-origin' header is present on the requested resource. I found that it was a "cross-origin problem" caused by Javascript Security. I found many solutions, such as setting cgi proxy and CORS (cross-origin resource sharing) when I tried it, but somehow I didn't succeed, I did not take it into consideration due to the time constraints. Finally, I found the article [Geoserver-users] CORS for jetty 6.1.8 (Geoserver 2.x) and solved, solve the problem according to its settings:

Solution steps:
1. Download the ZIP file from here, decompress it, and put it
 
  
\ Webapps \ geoserver \ WEB-INF \ classes folder.
 
2. Forward
 
  
Add the following configuration file to the web. xml file in \ webapps \ geoserver \ WEB-INF \ folder to allow cross-origin resource sharing for all domains
  
 
         
    
     cross-origin
          
    
     org.mortbay.servlets.CrossOriginFilter
      
     
     
      allowedOrigins
      
     
      *
       
          
           
     
      allowedMethods
            
     
      GET,POST
           
          
           
     
      allowedHeaders
            
     
      x-requested-with,content-type
           
        
   
           
    
     cross-origin
            
    
     /*
        
   

Restart GeoServer and wait a moment until cross-origin access is successful. Good luck. The main content of the original article is as follows:
Solve the problem. The original content is
I was looking on Geoserver cross domain support (no-proxy) recently and Imanaged to get it working by compiling custom filter for Jetty 6.1.8. Thefilter is based on CrossOriginFilter which is supplied with newer versionsof jetty-servlets.jar. I have fixed some white-space bugs and tested itwith OpenLayers 2.12, IE, FF and Chrome.You can follow the same rules as described here:http://wiki.eclipse.org/Jetty/Feature/Cross_Origin_Filter but:1.Do not include the jar. Instead, put content of this archivehttp://shanbe.hezoun.com/cors.zip into the
 
  \webapps\geoserver\WEB-INF\classes folder.2. use 
  
   org.mortbay.servlets.CrossOriginFilter
   insteand of
  
   org.eclipse.jetty.servlets.CrossOriginFilter
  3. do not use additional spaces in allowedHeaders defs (like this:"x-request-with, content-type")You can put follwing conf. inside the 
  
   \webapps\geoserver\web.xmlto allow CORS requests from all domains:
         
    
     cross-origin
          
    
     org.mortbay.servlets.CrossOriginFilter
      
     
     
      allowedOrigins
      
     
      *
       
          
           
     
      allowedMethods
            
     
      GET,POST
           
          
           
     
      allowedHeaders
            
     
      x-requested-with,content-type
           
        
   ... 
           
    
     cross-origin
            
    
     /*
        
   ..restart the geoserver and it should work.
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.