• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cookies or url rewriting

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic