aspose file tools
The moose likes Servlets and the fly likes Session ID changing within session Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Session ID changing within session" Watch "Session ID changing within session" New topic
Author

Session ID changing within session

Fred Rogan
Greenhorn

Joined: Nov 16, 2003
Posts: 9
Hi,

I am having a problem where the session id is changing (sometimes) after submitting a form to a servlet and responding to another page.

My jsp page has a html form with action="servlet/FCSpinalMuscularSurvey"

The servlet code is as follows:
public class FCSpinalMuscularSurvey extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{

response.setContentType("text/html");
String sNextPage = "/Page2.htm";

if (!sNextPage.equals(""))
{
response.sendRedirect(sNextPage);
}
}
}

When I try to get the session id from Page2.htm it has changed.

Has anyone else experienced this problem.

The code is redirecting properly just changing the session id. If I press refresh on the browser and try the same sequence there is no problem ie. the session id doesn't change. Any ideas would be great.

Cheers,
John
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12271
    
    1
When I try to get the session id from Page2.htm it has changed.

If you see a different session id, you have a different session object. There is no way for your code, or normal servlet container code to change the id, thats the whole idea.
Bill


Java Resources at www.wbrogden.com
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 568
Is it because your session has timed out while waiting for you to fill in the form?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56223
    
  13

"John van H",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Fred Rogan
Greenhorn

Joined: Nov 16, 2003
Posts: 9
The form is not timing out and changing session.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56223
    
  13

"John van H/Rid Appetit",

Perhaps you missed the "not obviously fictitious" part of the naming convention. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

bear
JavaRanch Sheriff
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Rid Appetit"

Please see Bear's previous post about 'fictitious names'

Thanks,
Dave.
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 568
The form is not timing out and changing session


And, are you sure you've turned on cookie support in the browser?
Fred Rogan
Greenhorn

Joined: Nov 16, 2003
Posts: 9
Cookie support is on but I wouldn't of thought this would affect the session state anyway.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56223
    
  13

Originally posted by Fred Rogan:
Cookie support is on but I wouldn't of thought this would affect the session state anyway.


How do you think the session is maintained?
Fred Rogan
Greenhorn

Joined: Nov 16, 2003
Posts: 9
After restudying the topics about session state/cookies etc I realised you guys may have a point. So I disabled my firewall which I thought was not affecting my cookies because of my settings. However this fixed the problem.

Thanks guys for putting up with my ignorance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session ID changing within session
 
Similar Threads
Pls help : I get error when i try to access servlet directly
How to give delay in JSP ?
Loosing sessions between pages
Assigning String object to bean class reference variable/jsp:usebean issue
actionlistener for selectBooleanCheckbox doubt?