2012-11-19 37 views
2

我正在嘗試從廣告客戶端(js)向Ec2 Tomcat7執行ajax調用。EC2上的CORS TOMCAT 7

我按照這裏的步驟在tomcat7上啓用CORS。

http://software.dzhuvinov.com/cors-filter-installation.html

它給了我

的XMLHttpRequest無法加載http://ec2-122-248-194-3.ap-southeast-1.compute.amazonaws.com:8080/Cocacard/FrontServlet。來源「http://192.168.2.3」是Access-Control-Allow-Origin不允許的。

我也試過在我的服務器端servlet代碼,

response.setHeader( 「訪問控制允許來源」, 「*」);

沒有運氣。

任何一個運行到這個b4的ec2 tomcat7?

問候 錘

回答

2

嘗試配置在web.xml中你的 「CORS過濾器」,有以下幾點:

<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.2.3</param-value> 
    </init-param> 
</filter> 
+0

感謝馬裏烏什。它運作良好。 – Hammer

+0

在這個例子中allowOrigin如何被參數化?對於我來說,在web.xml中對IP或域進行硬編碼是不可接受的。 –