• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp session keeps changing

 
tatyana markova
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I keep my jsp session from changing.
It only changes when I use the URL that is mapped to my web server. If I access my server using localhost, then the session does not change.
I would really appreciate any help with this.
Thanks,
Tatyana
Tatyana1217@yahoo.com
 
Alfonso Harding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using at the top of your code.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get a new session every time you call the server at a given address for the first time from a given browser instance.
Subsequent calls to the same server from the same browser instance will use the same session unless you specifically tell it not to by calling session.invalidate() somewhere in your code or if you wait longer than the set session timeout interval.
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the session mechanism uses either URL rewriting or a session cookie on
the client side.
If your browser has disabled session cookies, you will get a new session every time your page calls itself with a

or with a


To make sure your page adds the session id to the URL you can use

and work with the url variable from then on.
Bye,
J.
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeffrey Spaulding:
Hi,
the session mechanism uses either URL rewriting or a session cookie on
the client side.
If your browser has disabled session cookies, you will get a new session every time your page calls itself with a

or with a


To make sure your page adds the session id to the URL you can use

and work with the url variable from then on.
Bye,
J.

Correct. An alternative to a scriptlet that calls encodeURL() is to use the JSTL <c:url> action:
<c:url var="myURL" value="foo.jsp">
<c:param name="myParam" value="myValue" />
</c:url>
<a href="${myURL}">myLink</a> (if you use JSP 2.0)
<a href="<cut value="${myURL}" escapeXml="false" />">myLink</a> (if you use JSP 1.2)
The <c:url> action takes care of both "URL rewriting" (including the session ID in the URL), "URL encoding" of the parameter value (e.g., converting special characters to character entity codes), and converting context-relative paths to absolute paths that the browser understands.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic