My knowledge of EJB Session bean say:
1. Stateful Session Bean : Maintains the client state.
2. Stateless Session Bean : Does not maintain the client state.
Now I am developing Shopping Cart Example using EJB, Servlet, JSP and HTML pages.
My Project contains following pages:
6. AuthenticateBean – Stateful Session Bean
7. AutheticateBeanRemote – Remote Interface of Authenticate Bean
8. PurchaseBean – StatefulSession Bean
9. PurchaseBeanRemote -- Remote Interface of PurchaseBean
Session Bean with its remote interface is maintained in the ejb package.
1. textbox named “txtUser”
2. Password textbox named “txtPass”
3. Submit Button
On submitting the credentials, it will check for the authentication in the AuthenticateServlet.
public boolean authenticate(String user, String pwd)
The above method is exposed in AuthenticateBeanRemote Interface.
2. AuthenticateServlet contains
I have done lookup of AuthenticateBeanRemote and have created abr. Below some important code of AuthenticateServlet;
String user = request.getParamter("txtUser") ;
String pwd = request.getParamter("txtPassr") ;
boolean flag = abr.authenticate(user,pwd);
// then it will direct the control to User Page
User.jsp page will show me the UserID and some task that the authenticated user can do.
My question: is while redirecting the page to User.jsp from AuthenticateServlet, do I need to do URLRewritting to maintain the session or do I need to create separate HTTPSession Object or does the Stateful session bean will take care of session management on its own. i.e. no need to do anything, just transfer or redirect to User.jsp page .
User.jsp has purchase catalog of which the user will select products and click on purchase. On clicking purchase, it will take us to PurchaseServlet.
My question Now in the PurchaseServlet if I have written the code to access the methods in PurchaseBean, Whether it will be a guarantee that the authernticated and currently logged in user is accessing the methods so that only that person’s purchased items are visible and no mishap will occur regarding the user integrity.
PurchaseBean only contains the method to add the amount.
My Question: if at the same time 2-3 users are logging in the application, then whether by using the statefulsession bean, user integrity is maintained. OR do I need to use some other approach.
Please help me... I know these questions are silly but that’s the way the technology can be learned.
But only doubt i have that whether client state will be maintained accross 2 EJB irespective of whether one of them is Stateful or not. If so then how does it maintains?
Not sure I understand your question. If your client calls a stateless session bean, no state is maintained. If your client calls a stateful session bean, state is maintained. Or is your scenario more complex?
Both will be stateful. then state will be maintained.But how will be maintained if both are stateful.
But if , i have statefulsessionbean for authentication and productbean for purchasing products. and my productbean is stateless, then how can i maintain the user integrity here ie.e session management here. whether it is possible or not?