This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Unable to retain http session after cross domain AJAX call

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a scenario such that I need to make a cross-domain ajax call (using JSONP) and get the Session id from the other domain as a JSON object wrapped around a callback method as below:


The above code is jsonPPage.jsp running in a domain say example2.com Now in example1.com, I am having a jsp page, say page1.jsp where I have a javascript method where I am making a Jquery-Ajax+JSONP call and getting the "sessionID" from example2.com/jsonPPage.jsp



I need to save the retrieved session id in the current session as a session attribute. For this, I am calling a method saveRetrievedSessionIdInCurrentSession(example2SessionId); and within that I am making a local AJAX call to a simple Servlet where I can retrieve the session from the request and save the example2SessionId as a session attribute.


Within TestServlet1, I am trying to do the following:


But within my TestServlet1 doPost() method, when I try to retrieve the session by request.getSession(), it is creating a new session. I confirmed it by doing a sysout of request.getSession().getId(). This is giving a different id that what I get when the page gets loaded initially. Basically I am not able to retrieve the session which user is associated with when the page got loaded initially.

This kind of behaviour is happening only after a cross-domain ajax call. Please tell me how can I retrieve the initial session (which means request.getSession() should not give a new session, rather it should return the existing session associated with the user)?
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!