Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sessions and EJB

 
shawn kennedy
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A few things i am confused about.
1)Say i have a user name and password for a user to log into my system.First i check if he is a registered user and then allow him to log into the system.Now my system consist of jsp servlets and ejb so wht i want to do is first set up a session the moment he logs in and then retreive the session value on each page so tht i know who is logged in on each page.How do i do tht do i have to use a HttpSession or cookie.And if i use any of these how do i get the value on each page after i set it on the first page in my application.Pls help.
2)Also i wanted to know why BMP bean is used to manage customers(CustomerEJB) in the Duke Banking Application of suns j2ee tutorial one could have used CMP also isnt it.
3)Also how do i maintain session info in EJB.

Pls help.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)Say i have a user name and password for a user to log into my system.First i check if he is a registered user and then allow him to log into the system.Now my system consist of jsp servlets and ejb so wht i want to do is first set up a session the moment he logs in and then retreive the session value on each page so tht i know who is logged in on each page.How do i do tht do i have to use a HttpSession or cookie.And if i use any of these how do i get the value on each page after i set it on the first page in my application.Pls help.

A fairly standard way is to store some kind of login token object into HttpSession. For example:
// executed during login
MyLoginToken loginToken = new MyLoginToken();
session.setAttribute("logintoken", loginToken);
where the MyLoginToken class would include some information about the login such as the principal (who logged in), type of credentials used (how did the user authenticate himself), time of login (for login timeout behavior), etc.
Now you can retrieve this token from the HttpSession with the following piece of code:
// get the login object from HttpSession
MyLoginToken loginToken = (MyLoginToken) session.getAttribute("logintoken");
2)Also i wanted to know why BMP bean is used to manage customers(CustomerEJB) in the Duke Banking Application of suns j2ee tutorial one could have used CMP also isnt it.

Don't know. Haven't explored the Duke app... It could be just to demonstrate BMP as a technology. There should be some documentation to tell you why they chose BMP instead of CMP.
3)Also how do i maintain session info in EJB.

You don't. If you're talking about Stateful SessionBeans, you don't need to do anything in order to maintain session info. Stateful SessionBeans work so that the bean instance is guaranteed to maintain its internal state (i.e. instance variables) between method calls. The key is to maintain the reference on the client-side since you must call the same instance...
[ July 15, 2003: Message edited by: Lasse Koskela ]
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1) You should consider using a Filter to perform this kind of action, it'll make your app easier to maintain and understand
2) Problably jus to demonstrate the tecnology, as if u have a ejb 2.0 compliant app server u should always consider using CMP that gives u considerable advantages over BMP.
3) Stateful session bens are build for this
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!