37395

Allow cross domain scripting in mvc web application

Question:

I have a web application and im using spring mvc. I need to allow cross domain scripting (i need that a web service that i externalize can be accessed by javascript). I wrote a crossdomain.xml and i put it under the WEB-INF folder. This is my crossdomain.xml

<?xml version="1.0" encoding="UTF-8"?> <cross-domain-policy> <allow-access-from domain="*" /> </cross-domain-policy>

I have searched around and saw that the crossdomain.xml should be accessable from this URL: "<em>localhost:8080/crossdomain.xml</em>"<br /> the thing is that the mvc is rerouting the request to the main controller (with RequestMapping annotation of "/"). How can i overcome this using spring mvc?<br /> Thank you.

Answer1:

crossdomain.xml is used <em>only</em> by flash, so that's probably not what you actually want.

If you want cross domain xhr requests done with javascript, you should be using either CORS or JSONP, see this <a href="https://stackoverflow.com/questions/10047584/browser-doesnt-follow-redirect-from-an-ajax-response-php-generated-response-i/10048020#10048020" rel="nofollow">related question</a>

CORS example:

access-control-allow-origin: http://api.example.com access-control-allow-credentials: true

JSONP example (with jQuery, requires server side support):

$.ajax({ type: "GET", url: "https://domain.com/jsonp-service", dataType: "JSONP" });

Answer2:

There is a special integration between jax rs jersey implementation and spring. all explained in this blog <a href="https://blogs.oracle.com/enterprisetechtips/entry/jersey_and_spring" rel="nofollow">Jersey Spring integration</a>

Recommend

  • Extracting Remote endpoint Object from Spring websocket session
  • CFNetwork SSLHandshake failed (-9806) & (-9800) & (-9830)
  • Accessing Windows Azure Queues from client side javascript/jquery
  • Linux over commit heuristic
  • Splash Screen will not display
  • Xamarin Android | Layout style
  • How to get current document uri in XSLT?
  • JBoss External Properties Files in Classpath
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • Bad request using file_get_contents for PUT request in PHP
  • Jquery UI tool tip close icon
  • Paperclip, set path outside of rails root folder
  • When to use `image` and when to use `Matrix` in Emgu CV?
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Uncaught Error: Could not find module `ember-load-initializers`
  • output of program is not same as passed argument
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • Apache 2.4 - remove | delete | uninstall
  • Akka Routing: Reply's send to router ends up as dead letters
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper folder structure for lots of source files
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • Append folder name and increment by 1 using batch script
  • Checking variable from a different class in C#
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize