I am having a problem with Tomcat and backbone using CORS. The setup is as followed: - Backbone sends a post request to tomcat - Tomcat checks using web.xml and custom filter (link: CORS FILTER IN JAVA) and uses CORS on this request - request gets processed through the CORS filter and matches - Response is sent back to backbone and fails.
Backbone does 2 request, first 1 is a preflight request and returns a 200 status (which is good), second request returns a 302 status because my jsessionid gets changed and wants to redirect to login page which fails (not ok).
In backbone I have already added this:
data: param,
// contentType: 'application/x-www-form-urlencoded; charset=utf-8',
dataType: 'jsonp',
crossDomain: true,
//async: true,
xhrFields: {
withCredentials: true
},
And in tomcat this:
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>http://localhost:8888 http://localhost:8881</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified, X-File-Name</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
But still no luck. My JSESSIONID doesn't get send to my tomcat and that causes a new JSESSIONID to be created and makes my request fail.
Any help would be useful :)
I am using Tomcat 6.0.16 and Jquery 1.8
Change the
dataType
to'json'
.