Solved

EJB - Struts - MVC

Posted on 2006-07-16
9
991 Views
Last Modified: 2013-11-24
Hi Guys,

I'm in the initial stages of learning EJBs and Struts.

My question is - When I say ....I'm using Struts in a Project it means i'm using MVC model-2. And in the same project can I use EJB's . If Yes, can you explain in terms of using Struts and EJBs combinely.


Thank You,
Jagadeesh
0
Comment
Question by:jagadeesh_motamarri
9 Comments
 
LVL 16

Accepted Solution

by:
suprapto45 earned 125 total points
ID: 17119409
Hi,

If you would like to combine both EJB and Struts together, here is what we normally do.

Struts will only manage the flow of the application as well as doing all the validation to and from JSP. JSP interacts with Struts. Then Struts action will call the method in the session bean to do all the business logic. Normally, business logics are located in session bean and not in the Struts.

David
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17119756
then EJB is your controller
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 125 total points
ID: 17120055
jagadeesh_motamarri,
> I'm using Struts in a Project it means i'm using MVC model-2. And in
> the same project can I use EJB's . If Yes, can you explain in terms of
> using Struts and EJBs combinely.

Yes you can use EJBs in the same project. JSPs via Struts will be there for the View (i.e. for displaying the data to the user), EJB and struts action classes will be the controller (i.e. will be loading the data from the database and will do the appropriate actions, e.g. calculate things etc) and the data in the database will be the Model. You will need to be calling EJBs from your JSP pages.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 4

Assisted Solution

by:Meritor
Meritor earned 125 total points
ID: 17122674
>Yes you can use EJBs in the same project. JSPs via Struts will be there for the View (i.e. for
>displaying the data to the user), EJB and struts action classes will be the controller (i.e. will
>be loading the data from the database and will do the appropriate actions, e.g. calculate
>things etc) and the data in the database will be the Model. You will need to be calling EJBs
>from your JSP pages.

You have suggested to make EJBs as Controller and call them through JSP that is not a good practice.
Generally, only business logic should be written in EJB.
Only Struts ActionServlets and struts-config.xml should only be the controller.
And your Action classes should call EJB which contains the core business Logic.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17122729
Actually no. I have suggested to use EJBs *and* Struts actions as controller :)

But I will agree with you, it's not a good practice to call EJBs straight from JSP, although nothing prevents you of doing so.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 17129880
http://java.sun.com/blueprints/guidelines/designing_ enterprise_applications_2e/web-tier/web-tier5.html
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 125 total points
ID: 17129885
Oops :) java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now