This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cookies or url rewriting  RSS feed

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know its an age old question
but still i have to ask this one
The session api can use cookies or url-rewriting for maintaing sessions
Now what I need is a way not to use cookies, but only use url-rewriting
how can i make sure that session api does not use cookies
I see methods in javax.servlet.http. HttpServletRequest
like isRequestedSessionIdFromCookie()
but dont know how to set it
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i remember right, it depends on the browser preferences. the servlet tries to set cookies but if they are disabled in browser it moves to session tracking stuff with urlencoding.
read more here:
http://csajsp-chapters.corewebprogramming.com/CSAJSP-Chapter9.pdf
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Asher Tarnopolski:
if i remember right, it depends on the browser preferences. the servlet tries to set cookies but if they are disabled in browser it moves to session tracking stuff with urlencoding.
read more here:
http://csajsp-chapters.corewebprogramming.com/CSAJSP-Chapter9.pdf

Sort of. URL rewriting must be done in the JSP in order to pass the session id. i.e. for a link to "myJsp.jsp" the session ID is not appended unless you use URLEncoder.encode("myJsp.jsp") to write the link. At that point, it is up to the servlet engine to determine how to encode it. In WAS, you either enable or diable URL encoding. With it enabled, the resulting link is something like "myJsp.jsp;ab234alkj2349023" which the browser understands is a session ID to pass back to the server.
If a browser has cookies 100% disabled and you don't use URL rewriting, the user will get a new session every time.

The Struts html:link tag takes care of all this for you, so if you need to maintain session across pages, it's a lot easier to use this tag
<html:link href="myJsp.jsp">link</a>
than
<a href="<%=URLEncoder.encode("myJsp.jsp")%>">link</a>
every time you create a link.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right, but you need response.encodeURL() method and not URLEncoder.encode() which encodes string into html format...
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Asher Tarnopolski:
right, but you need response.encodeURL() method and not URLEncoder.encode() which encodes string into html format...

DOH!
Of course, that's what I meant. :roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!