aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Questions" Watch "EJB Questions" New topic
Author

EJB Questions

Gaurav Dighe
Greenhorn

Joined: Jun 25, 2009
Posts: 21

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:
1. login.html
2. AuthenticateServlet.java
3. User.jsp
4. PurchaseServlet
5. PurchaseSuccessful.jsp
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.
Login.html contains;
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.
AuthenticateBean contains
public boolean authenticate(String user, String pwd)
{
if(anylogic)
return true;
else
return false;
}
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);
if(flag)
// then it will direct the control to User Page
else
out.println("Failure");

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.


Thanks & Regards,
Gaurav Dighe
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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

Yes.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Gaurav Dighe
Greenhorn

Joined: Jun 25, 2009
Posts: 21

Hi paul,
thanks for your answer.
thats means: Stateful Sessionbean will take cared of evenrything maintaining the client state as long as user is logged in, maintaining the integrity of the user.

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?

Please reply back
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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?
Gaurav Dighe
Greenhorn

Joined: Jun 25, 2009
Posts: 21

Sir,
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?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Both will be stateful. then state will be maintained.But how will be maintained if both are stateful.

The implementation details will vary from server to server. All you need to care about is that state is maintained.

You can't maintain state in a stateless bean. However, your stateless bean's methods presumably return something after the purchase? If so, this is what you can add to the stateful beans state.
Gaurav Dighe
Greenhorn

Joined: Jun 25, 2009
Posts: 21

Sir Sorry, But actually i am new to EJB.
How we can get, add to and remove from Stateful Session Bean State. Please elaborate with some code for my understanding.


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Typically you would have some sort of instance variable you store state in (e.g. a Collection of some sort). You would just add to that. Nothing more to it really.

The cart example of the JEE tutorial demonstrates this
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3097
    
  40

Gaurav, please UseAMeaningfulSubjectLine instead of something like "EJB Questions".


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
 
 
subject: EJB Questions