问题
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:
"localhost:8080/crossdomain.xml"
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?
Thank you.
回答1:
crossdomain.xml is used only 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 related question
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"
});
回答2:
There is a special integration between jax rs jersey implementation and spring. all explained in this blog Jersey Spring integration
来源:https://stackoverflow.com/questions/11377994/allow-cross-domain-scripting-in-mvc-web-application