File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes strange problem using jsp and servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "strange problem using jsp and servlet" Watch "strange problem using jsp and servlet" New topic
Author

strange problem using jsp and servlet

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
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


Subbu
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
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

Joined: Jun 22, 2001
Posts: 73
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

Joined: Apr 02, 2001
Posts: 1157

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strange problem using jsp and servlet