Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to implement business logic in a java bean/ejb

 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i have to seperate the business logic from my servlet/jsp using beans/ejb.
please give me some example of how to go about it..
thanks..
nidhi
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Just pass the method parameters from your jsp's or servlets to your ejb's where all your business logic is residing.

For eg:-

<pre>
<%@ page import="javax.naming.*"%>
<%
Context ctx=new InitialContext();
BeanHome ejb = (BeanHome) ctx.lookup("Bean");
// additional code here
%>
</pre>

Call your ejb's through look-up and pass the required parameters
for further processing of the request.

Regards

Anurag
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you can put the business logic in session beans.

Here is the tutorial giving example for that-
http://www.tusc.com.au/tutorial/html/index.html
 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx alot Anu, Damanjeet for the help.

the tutorial seems to be really good.

nidhi
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidhi,
How much comfortable are you with these technologies?
If you have reasonable amount of knowledge of JSP/ Servlet and EJBs than i will recommend you to go for MVC architectute using struts framework.
MVC (Model View Controller) architecture seperates Business logic completely from the presenation layer, something what you are looking for.
 
Vijay Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidhi,
This is John,I have a very good solution of ur problem.U want to separate the business logic with the presentation logic.Just do one thing Make one Ejb,Any (Entity bean,Session Bean).So,in all we made one component.Then Ur presentation parts come to picture.Now just built JSP pages for presentation purpose,and any extra data connection if needed.And Use Servlet wherever necessary,like if u wanna to check for login,there for internal logic u can use servlet.It's very easy to do.Once u got familiar with the beans part.
 
Vijay Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now when u want to use the component.
1.Create the object for initial Context.
2.Lookup.
3.Create Remote Interface Object to access the business menthod.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic