我在调用同一网络内另一台服务器的另一个网站中的 JS 函数时遇到问题。我的脚本按以下方式工作:
在服务器 1(IP:192.168.1.17)的页面中有一个表单,它有一个按钮,可以从服务器 2(IP:162.168.1.18)的页面打开一个弹出窗口并显示项目列表。通过双击列表中的一项,页面执行opener.setearProducto
函数,检索 aString 作为参数。但此时,Firebug 向我显示一条消息:“错误:访问属性 'setearProductos' 的权限被拒绝”并且脚本不起作用。这很奇怪,因为当我在同一台 PC 上测试它时,一切都完美无缺。
我在谷歌上搜索并注意到需要安装CORS。但是当我在两台服务器上安装它时,脚本仍然不起作用。我还尝试将标头Access-Control-Allow-Origin添加到 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>