This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm building a web 'face' for a simple scientific database, and am learning JSP, Servlets, EJB in order to build it. Later, I intend to implement a web service to provide the data in xml. However, I am still determining the purpose of the pieces and parts.
As I understand it, JSP is used solely for building html/xml front ends. JSP can access EJBs and servlets for increased functionality.
My question, when should I use a javabean over a servlet or vice versa? Is it better to handle business logic in servlets or in a bean? Lastly, if all I'm doing is returning data and require no stateful objects, should I just skip beans altogether? How would using one over the other affect creating a SOAP interface?
-------<br /> Aodhan H - Ad Astra Per Aspera<br /> -------
I will try to give you a reply, about how the different parts (JSP/Servlets/EJB) are put together.
The JSP and / or servlets are basically the code for communicating with the user (the browser) by generating HTML pages, and receiving HTTP requests. Try to look at Struts (from www.apache.org), for getting a idea, about how to get JSP and Servlets to talk together.
Behind that, you properly need some 'business logic' like getting data from a DB. This can be coded in 'pure old java classes' or in EJB's. The last is most HIP, but not necessarily most effective. EJB gives you transaction, security, and scalability, but if you don�t need any of this, you can as well go for the other solution, ('pure old java classes'). EJB requires more understanding of java.
You are able to use web services in both models. You need some sort of Servlet engine in order for use JSP/Servlets (for a free one, try Tomcat from apache) This can also be EJB container (Weblogic or JBoss just to mention some). These containers will all be able to receive SOAP calls, and there by allowing you to Web Service enable your application.
Thanks, Jan. I'm using Tomcat for my project ( I don't control the server ), so I'll probably look into using servlets more than EJBs ( also not concerned with transaction security, nothing sensitive will be transmitted ).
When you refer to 'pure old java classes', do you mean servlets?
Joined: Nov 22, 2008
No, just any type of classes, not to do with EJB.
You can call any classes from your Servlets, letting them do he business logic, like accessing the DB. By having the logic separated form the Servlets, doing the presentation, it is easy to add a new presentation layer, like let any web services using the same logic, without duplicating the code.
Okay, I was misunderstanding the purpose of servlets. They handle presentation layer actions? I think I got your meaning on the classes now, just bundle the package that handles business logic into the server's library, right?