jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Session Management with Ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Session Management with Ajax" Watch "Session Management with Ajax" New topic

Session Management with Ajax

Satish Dasari

Joined: Dec 10, 2008
Posts: 2
Hi All,
I have a problem with session management with ajax requests. In my application I'm using struts1.2.9 and hibernate 3.
In my usecase I've to check the user existance in session. If user exist in the session then it should get into the application, if not it should redirect to login page.
I used filter to check the session existance and redirecting the request to the login page if user doesn't exist.

But here my problem is in my application there several ajax requests are there.
For every request its checking for the session and if the session doesn't exist its redirecting to the login page.
everything working fine with normal requests. But when any ajax request occurs the login page is loaded in a specific "DIV" .

So instead of loading the entire page , some divs only getting loaded with the login page.

i don't know how to solve this problem.
My code is given below

and my web.xml form mapping is

Thanks in advance

Satish Raj.

Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

You didn't show us the AJAX code. Anyways, in your AJAX code, try to see the response's status code. If the status code of the response is 307 (or anything between 300 and 399), then that means that the AJAX call was redirected. Then you can redirect the page in JS using location.href and the Location header of the response. Similar examples can be seen here and here...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link: http://aspose.com/file-tools
subject: Session Management with Ajax
jQuery in Action, 3rd edition