• 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

switching between cookies and url rewritten, HELP

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
In my web application (a book store), I have a servlet that add a specific item to the shopping cart.
for session tracking, I have used the HttpSession object for the servlets and JSPs.
you know like:
session.setAttribute("cart", "some item");
and the link that invokes this servlet is :
----------------
<a href="/store/add?itemId=<%= rs.getString("isbn") %>">Add To Shopping Cart</a>
----------------
every thing work fine, but when disableing the cookies, a NullPointerException is thrown.
can I detect if the user is disabling the cookies ? and if disabling them
How to switch to url rewrite, and if switch, how to keep tracking the user ?
(I mean, every url will have a jsessionid and a long id, and if the user clicks View Shopping Cart, then how my JSP can benefit from the jsessionid number, how to extract it ?)
please help me, coz this subject is very important to me...
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not need to care if a user has disabled cookies (unless you want to explicitly set a 'C'ookie. There is no need to 'switch' to using cookies or url rewriting, as there is a method that takes care of this for you.

All you need to do, to enable URL Rewriting (at least in some containers) is to make sure any and all links (and form actions) are sent through the response.encodeURL() method.

So your HTML would be:
<a href="<%= response.encodeURL("/store/add?itemId=" + rs.getString("isbn")) %>">Add To Shopping Cart</a>
That is *it*. The jsessionid that is inserted into that URL does not need to get extracted by you. The container does that for you, and you access the Session in the normal way. If the user has cookies enabled, the container will not re-write the URL, so that's why you don't need to worry about 'switching' yourself.
[ March 31, 2004: Message edited by: Mike Curwen ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am not able to replicate the NPE, can you guys give us the exact scenario and the code.
thanks,
prasadh
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic