I am new to "J2EE". I am codeing a simple web application. In this application i am providing the functionality of shopping cart..NOW the problem is that I want to check weather user is LOGEDIN or not before user adds any item in shopping to shopping cart... How can we do this checking... I am thinking of setting an attribute at session level say f=0 and check this attrib when user clicks on add item button if ist ZERO tell user to sign in otherwise procced with add item.. BUT session are supposed to start when user logsin...
I am a bit confused and dont know weather I was able state my problem clearly but if somebody can usnderstand it an provide a sloution I will be very thankful....
(2) Create a filter and map it to *.jsp. ie., any request to any jsp page will pass through this filter.
Your filter logic should be something like:
If this is the login page, then no further check is required. If this not the login page, check whether the 'loggedInUser' attribute exists in the session or not. If it doesn't redirect the user to the login page.
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Joined: Aug 02, 2006
hi thanks Lynette Dawson
but I dont want to force login.. a user will be able browse items without signing in as soon as he clicks on add item we need to check weather he is logged or not..
there can be two cases: 1) as soon as user access our web site first thing we ask him to sign in..and start a session...
2) OR he can browse the web site without signing in (and no session is created) but when he clicks on add item we need to check first if user is logged in or not and then procced accordingly. because first thing a user may do is to login and then procced with the shopping...but he may not do so... so how can we determine weather he is logged in or not before clicking on add item...... I hope this time I am more clear....
Joined: Aug 25, 2005
ok in that case, its just a matter of checking whether the "loggedInUser" attribute exists in the session or not (when the user attempts to put an item in the shopping car).
Joined: Aug 02, 2006
Hey Lynette Dawson thanks a lot...
I knew the solution will be easy... its just that I am new to servlets & JSP and I dont know all the options available.... Thanks again...
subject: How to know login & logout status of user