• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused ,need some help in coding  RSS feed

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am developing a bookstore application for my school project using jsp,Java beans and servlets.
On my home page , user will search for books using some criteria(like title ,isbn etc).It pulls the existing records from database matching the criteria.
for example
Author Title Price ISBN
Jason Programming 25 2147483647 AddTo Cart
Jason TCP/IP 55 2897645 AddTo Cart
Jason TCP layers 35 2341095 AddTo Cart
when the user clciks on the AddTo Cart button i am calling addtocart.jsp , here i want to check whether that user is already loged in or not if not forward to login page.Here i am confused about the code how to check whether the user loged in or not.I know I have to use sessions.But not understabding exactly how to write that.
I really aprreciate any kind of help.
Archana
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, what most ppl seem to do is:
assuming you have an object/bean that contains all the user-relevant info, you load that into the session once the user has been logged in. Then on every page that requires the user to be logged in, you check for the presence of that variable in the session. If it is not there, then redirect the user to the login page. You could also pass along the path of the sending page so that after login, the user gets redirected back.
some code snippets:
// setting session variables
(assuming userinfo has been loaded)
HttpSession session = request.getSession(true);
session.setAttribute("userinfo", userinfo);
// checking for session variables
UserInfo userinfo = (UserInfo) session.getAttribute("userinfo");
if (userinfo == null) {} // not logged in
else {} // logged in
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Phil, I really appreciate your help.

Archana
[ March 23, 2003: Message edited by: Archana Annamaneni ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!