在 Silverlight 应用程序的 java servlet 上启用跨域调用

发布于 2024-12-11 13:58:23 字数 1596 浏览 0 评论 0原文

我有一个带有 OData4j 库的 java servlet,我想对其进行配置,以便可以从 Silverlight 应用程序发出 HTTP POST 请求。

我的 web.xml 文件如下所示:

<servlet>
  <servlet-name>OData</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
     <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
     <param-value>org.odata4j.producer.resources.ODataResourceConfig</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>OData</servlet-name>
    <url-pattern>/myService/*</url-pattern>
</servlet-mapping>

我尝试将其添加到我的 web.xml 文件中:

<servlet>
  <servlet-name>CrossDomain</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
     <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
     <param-value>org.odata4j.producer.resources.CrossDomainResourceConfig</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CrossDomain</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

但它不起作用。我还尝试将“crossdomain.xml”和“clientaccesspolicy.xml”文件添加到我的资源目录中,但这也不起作用。使用 Silverlight 应用程序发送 HTTP POST 请求时,我仍然收到 SecurityException。

任何提示将不胜感激。

谢谢

I have a java servlet with the OData4j library and I want to configure it so I can make HTTP POST request from a Silverlight application.

My web.xml file looks like this:

<servlet>
  <servlet-name>OData</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
     <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
     <param-value>org.odata4j.producer.resources.ODataResourceConfig</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>OData</servlet-name>
    <url-pattern>/myService/*</url-pattern>
</servlet-mapping>

I've tried adding this to my web.xml file:

<servlet>
  <servlet-name>CrossDomain</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
     <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
     <param-value>org.odata4j.producer.resources.CrossDomainResourceConfig</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CrossDomain</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

But it doesn't work. I also tried adding the "crossdomain.xml" and "clientaccesspolicy.xml" files to my resources directory but that also doesn't work. I still get a SecurityException when sending a HTTP POST request with my Silverlight application.

Any hints would be greatly appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£烟消云散 2024-12-18 13:58:23

事实证明,实例化 CrossDomainResourceConfig 确实启用了“crossdomain.xml”和“clientaccesspolicy.xml”文件。问题是它们可以通过以下 URL 获得:/myService/crossdomain.xml/myService/clientaccesspolicy.xml

但是,Silverlight 运行时会在服务器根目录中查找这些文件(例如:/clientaccesspolicy.xml),

通过在服务器根目录中手动添加这两个文件,它解决了该问题。

Turns out that instantiating CrossDomainResourceConfig does enable the "crossdomain.xml" and "clientaccesspolicy.xml" files. The thing is that they are available at the URL: /myService/crossdomain.xml and /myService/clientaccesspolicy.xml.

However, the Silverlight runtime looks for those files at the server root (eg: /clientaccesspolicy.xml)

By adding both of those files manually in the server root, it fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文