我有一個問題,可以調用另一個網站中另一個服務器內的JS功能。我的腳本的工作原理如下:跨域javascript函數調用?
在服務器1(IP:192.168.1.17)的頁面中有一個按鈕,可以從服務器2(IP:162.168.1.18)的頁面打開一個彈出窗口,並顯示項目列表。通過雙擊列表中的一項,頁面執行opener.setearProducto
函數,檢索aString作爲參數。但在此刻,Firebug向我顯示一條消息:「錯誤:權限被拒絕訪問屬性'setearProductos'」,並且該腳本無法正常工作。 這很奇怪,因爲當我在同一臺PC上測試它時,所有工作都完美無缺。
我是谷歌搜索,並注意到需要安裝CORS。但是當我在兩臺服務器上安裝它時,腳本仍然不起作用。我也嘗試將頭文件訪問控制 - 允許來源添加到JSP文件,但也沒有工作。
我不知道問題是否與應用程序中使用的框架有關:Struts 2和Spring。
我需要幫助,因爲我不知道該怎麼做。
我附上我的web.xml如果有幫助。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- CORS -->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<!-- configuraicond e Struts y Spring -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>sistema.cron.TareasProgramadas</listener-class>
</listener>
<listener>
<listener-class>sistema.base.logica.ControlServicios</listener-class>
</listener>
<!-- inicio CORS -->
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- inicio Struts -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
120
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
*當我在同一臺PC上測試它的所有作品完美*可能是因爲您的電腦被允許遠程訪問到其他服務器的資源或二者的Web應用程序部署在同一臺服務器,因此所有的權限,它們之間共享資源已啓用。 –