You might encounter an error like this when using jquery Ajax Post requests
XMLHttpRequest cannot oad http://xxxxxx. Origin http://xxxxxx is isn't allowed by Access-control-allow-origin.
This is an issue with Ajax cross-domain access permissions, and the server side does not accept HTTP requests from a different IP address from a script file. Solving this problem requires a server-side configuration that allows the server side to accept HTTP requests from script files from different domains. A simple workaround is to configure the jetty cross Origin Filter on the server side.
First you need to download Jetty-servlets.jar. http://central.maven.org/maven2/org/eclipse/jetty/jetty-servlets/. Then import the Jetty-servlets.jar into the Web-inf/lib folder. Finally, configuring some simple parameters on the Web. xml file allows the server side to allow cross-domain access. A typical configuration is this:
1 <Web-app>2 3 <Filter>4 5 <Filter-name>Cross-origin</Filter-name>6 7 <Filter-class>Org.eclipse.jetty.servlets.CrossOriginFilter</Filter-class>8 9 <Init-param>Ten One <Param-name>Allowedorigins</Param-name> A - <Param-value>*</Param-value> - the </Init-param> - - <Init-param> - + <Param-name>Allowedmethods</Param-name> - + <Param-value>Get,post,options,delete,put,head</Param-value> A at </Init-param> - - <Init-param> - - <Param-name>Allowcredentials</Param-name> - in <Param-value>True</Param-value> - to </Init-param> + - <Init-param> the * <Param-name>Allowcredentials</Param-name> $ Panax Notoginseng <Param-value>True</Param-value> - the </Init-param> + A </Filter> the + <filter-mapping> - $ <Filter-name>Cross-origin</Filter-name> $ - <Url-pattern>/rest/*</Url-pattern> - the </filter-mapping> - Wuyi </Web-app>
Jetty Cross Origin configuration method
Next, explain the specific meaning of the parameter:
Allowedorigins: A domain or link address that allows cross-domain access, multiple addresses are separated by commas, and the default value is "*", which means that access requests from all domains are accepted.
Allowedmethods: Acceptable HTTP request method, multiple methods separated by commas, default to get, Psot, HEAD.
Allowcredentials: The default is true if trusted requests are allowed to access resources.
For additional detailed configuration, refer to the official documentation:
Http://www.eclipse.org/jetty/documentation/current/cross-origin-filter.html
Jetty Cross Origin Filter solutions for jquery ajax access across domains