Tomcat cross-domain request

Source: Internet
Author: User

Tomcat a requests data in Tomcat B (I am different on the same machine with 2 Tomcat ports, time is measured on different machines)

The blogger uses AJAX requests for data in a request B, using the following method to

In the requested Tomcat B application, add the following code to Web. XML:

Add the following jar to the Tomcat B application:

Cors-filter-1.7.jar; Java-property-utils-1.9.jar

<!--Tomcat cross-domain request start-up <filter> <filter-name>CORS</filter-name> <filter-class>com.thetransactioncompany.cors.corsfilter</filter-class> <init-param> <param-name>cors.allowOrigin</param-name> <param-value >*</param-value> </init-param> <init-param> <param-name>cors.supported Methods</param-name> <param-value>get, POST, HEAD, PUT, delete</param-value> </init -param> <init-param> <param-name>cors.supportedHeaders</param-name> < Param-value>accept, Origin, X-requested-with, Content-type, last-modified</param-value> </init-param&gt        ; <init-param> <param-name>cors.exposedHeaders</param-name> <param-value>set-c ookie</param-value> </init-param> <init-param> &LT;PARAM-NAME&GT;CORS.SUPPORTSC Redentials</param-name> <param-value>true</param-value> </init-param> </filter> <!--request Filter Start-up <filter-mapping> <filter-name>CORS</filter-name> <url-pattern>/*</url-pattern>
<!--for security reasons, you can write the requested path in the filter--</filter-mapping> </filter-mapping> <!--The request filter ends--& lt;! --Tomcat cross-domain request ended--

For security reasons, the requested path can be written in the filter

Multiple filter notation:

    <filter-mapping>        <filter-name>CORS</filter-name>        <url-pattern>/xxx</ url-pattern>    </filter-mapping>    <filter-mapping>        <filter-name>cors</ filter-name>        <url-pattern>/XXX</url-pattern>    </filter-mapping>    < filter-mapping>        <filter-name>CORS</filter-name>        <url-pattern>/xxx</ url-pattern>    </filter-mapping>    <filter-mapping>        <filter-name>cors</ filter-name>        <url-pattern>/XXX</url-pattern>    </filter-mapping>

Code reference: http://www.cnblogs.com/chiyouguli/p/4283349.html

PS: This article for Bo Master original, reprint please indicate source: http://www.cnblogs.com/Y-zhiwei/.

Tomcat cross-domain request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.