Cross domain Ajax filter ver. 1.2

This is a Java servlet filter (as per Servlet API 2.3). This filter lets you allow cross domain Ajax requests to your resources. Firefox 3.5 allows you to make XMLHttpRequests cross domain (in other words code loaded from some domain foo.com can make XHR requests to bar.com). Mozilla's spec offers a special HTTP header for that. This filter lets you add such a header to your site so cross domain requests could be allowed for existing web applications.

How to use it:

a) download crossdomainajaxflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml. By default filter allows cross domain requests from any domain
 


<filter>
  <filter-name>CrossDomainAjaxFilter</filter-name>
  <filter-class>com.cj.access.CrossDomainAjaxFilter</filter-class>
</filter>

You can limit cross domain requests to the particularly domain only. An optional initial parameter domain describes that:
 


<filter>
  <filter-name>CrossDomainAjaxFilter</filter-name>
  <filter-class>com.cj.access.CrossDomainAjaxFilter</filter-class>
  <init-param>
    <param-name>domain</param-name>
    <param-value>http://allowed_domain.com</param-value>
  </init-param>
</filter>

d) describe a mapping for this filter in web.xml. E.g.:
 


<filter-mapping>
  <filter-name>CrossDomainAjaxFilter</filter-name>
  <url-pattern>/json/*.jsp</url-pattern>
</filter-mapping>

in this example filter will be on for the each .jsp file in /json subdirectory.

   For downloading:

    Cross domain Ajax filter package:  crossdomainajaxflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in Coldtags: