Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading a servlet by ajax call but not able to retrieve session on servlet  RSS feed

 
Pan Jain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet. I create session data in this servlet and forward request to a jsp.
In this jsp I am getting session data. From jsp I do ajax call and load a servlet.
Problem is that after ajax call session data in not available in servlet. What could be the reason?
 
Joe Areeda
Ranch Hand
Posts: 334
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ItsPankaj,

I'm a bit confused by your description is this what's happening?

A browser hits the container at starts a session (call it S1) and starts a servlet (V1)

That servlet makes an "AJAX" call to another servlet (V2) and you're looking for session data from S1?

If so the problem may be you're not in the same session on V2. For one thing the "AJAX" call is originating from a different client, your servlet not the original browser so it won't be using the session cookie (assuming cookies).

Another detail is that AJAX is not the right term here. I think REST is what you mean as AJAX is a javascript construct.

I am just guessing.

Joe
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From jsp I do ajax call and load a servlet.

[picky-mode] AJAX calls are made from a browser based on HTML/Javascript which may or may not have been loaded by requests to a JSP. Using the wrong terminology conceals logical errors.[/picky-mode]

If this was my problem I would look at the actual HTML page as loaded on the browser using a browser content plugin. Particularly the URL being used for the AJAX call.

As Joe suggested you may not even be seeing the same session.

Bill
 
Pan Jain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe, William,

Thanks for reply!
See I am creating session on Servlet say ST1. Now I am forwarding request to a jsp and my session data of ST1 is available in jsp.
Next I am making an AJAX call and calling another Servlet say ST2. Now problem is that session data is not available to ST2.
Its is creating a new session for ST2 servlet. I just want to pass my existing session to ST2 servlet. Is it possible?

Here is my AJAX call code snippet:


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote=ItsPankaj
See I am creating session on Servlet say ST1. Now I am forwarding request to a jsp and my session data of ST1 is available in jsp.
Next I am making an AJAX call and calling another Servlet say ST2. Now problem is that session data is not available to ST2.
Its is creating a new session for ST2 servlet. I just want to pass my existing session to ST2 servlet. Is it possible?


My guess is that the ST2 servlet is not in the same web app as ST1. Sessions are only tracked within a web application.

Alternate explanation, something is wrong with your code in ST2.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!