• 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

strange problem using jsp and servlet

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I want to find out if cookies are enabled or not in a client's browser.for this what i am doing is, first in one of the jsp pages i set up a cookie and then when the user clicks on the submit button he is forwarded to a servlet.this servlet checks for existence of the cookie set by the jsp page.if the cookie is there then the browser supports cookies otherwise not.my problem comes in here.
in the servlet when i try getting a session using
"HttpSession session = req.getSession(true);"
i am able to find out if the browser supports cookies.but on the other hand if i use
HttpSession session = req.getSession(false);
i dont get any output from the servlet.my question is, since the jsp page has already set up a session, why doesn't the second method works?
any help would be greatly appreciated.
Subbu
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Subbu,
HttpSession is to be used as an alternative for cookies.If you are not getting a HttpSession object with req.getSession(false), then probably the JSP from where you forwarded the request to the servlet didn't create a session instance.
Hope this helps,
Sandeep

 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandeep,
can u think of any reason as to why the session is not set up in the jsp page.i am establishing a session using
session = request.getSession(true);
in the jsp page.
thanks in advance.
Subbu
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Subbu Aswathanarayan:
can u think of any reason as to why the session is not set up in the jsp page.i am establishing a session using
session = request.getSession(true);


This is possible only if in the page directive you have set the session=false.This would mean the page will not have session data.
However, if you have not set this, implicitly JSP engine will create this object for you and you would be getting it when you call the request.getSession(true).
Hope this helps,
Sandeep
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic