270 likes | 434 Views
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB. Outline. Big picture Servlets JavaServer Pages EJB. EJB Server. Web Server. Browser. DB. EJB. Servlet. HTML. DB. Browser. EJB. JSP. XML. Multi-Tiered Web-based application.
E N D
Overview of The Java Platform Solution for E-Business Applications :JSP, Servlet and EJB
Outline • Big picture • Servlets • JavaServer Pages • EJB
EJB Server Web Server Browser DB EJB Servlet HTML DB Browser EJB JSP XML Multi-Tiered Web-based application
What are Servlets? • Extend HTTP Server • Dynamic content • Servlets are lightweight • Run in web server process • exploit Java security • Built on Java Platform • Full access to Java APIs • Easy to develop. Write once, run anywhere
HTTP Requests & Response • Client makes HTTP request • Request is resolved to Servlet • Container • creates servlet • invokes init() • creates request and response objects • invokes service() • Sevlet interact with response • Container replies to HTTP request • Container may • invoke destroy(), dispose servlet at anytime
A servlet example public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("Hello World!"); out.println("<br>"); JspCalendar clock = new JspCalender(); out.println("Today is"); out.println("<ul>"); out.println("<li>Day of month: "); out.println(clock.getDayofMonth()); out.println("<li>Year: "); out.println(clock.getYear()); out.println("/<ul>"); out.println("</html>"); } }
As a JSP page <html> Hello World! <br> <jsp:useBean id="clock" class="calendar.JspCalendar"> Today is <ul> <li>Day of month:<%=clock.getDayofMonth()%> <li>Year: <%=clock.getYear()%> </ul> </html>
JavaServer Pages (JSP) • JSP builds on servlet semantics • “inside-out” servlets (JSP can be precompiled into Servlet to reduce start up time) • Benefits • Easier to author, separate presentation logic from business logic • Exploits: • server-side scripting • templates • encapsulation of functionality
The Problem • Developing enterprise applications is HARD • Developing enterprise applications is EXPENSIVE • Enterprise applications are a NIGHTMARE TO MAINTAIN • Enterprise applications are COMPLEX TO ADMINISTER
Why is it HARD? • Difficult to reuse application code across • hardware platforms • software platforms • servers • databases • Service needs grow more complex • threading • persistence • transactions
What is EJB? • It’s server component model • It’s part of Java platform for the enterprise • It’s a specification (for software interoperability) • It enables development and deployment of Java applications that are: • Distributed – via RMI • Scalable • Transactional • Secure
Distributed component models -we are in heaven ... IIOP IIOP IIOP CORBAServerService RMIServerService RMIClient JRMP
Advantages of server side component model • Using pre-developed pieces of application • Transparent access to the distributed services, i.e. hiding the complexity of the technical environment • Components can be shared across the Enterprise • Using tools to wire components together
EJB Main Components • Client • Any application or service requesting a service • Can be written in any language • Can’t access EJBs directly; must go through RMI and container • Name lookup via JNDI • EJB Servers • Contains and runs 1 or more containers • Resource management • process, thread, and connection pools • Remote management API
EJB Main Components • EJB Containers • Actually host the beans • Provide naming (via JNDI), life cycle, persistence, security, transactions through call interception • EJB Components • Are distributed, transactional, and secure • Simple, single threaded, and non-re-entrant • Developer or tool generated • Contain business logic
Roles in developing EJB • Enterprise Bean provider • Application Assembler • Deployer • EJB Server Provider • System Administrator
Varieties of EJBs • Session beans • Model application tasks • Not shared, client specific • Transient state • Short lived • Example – an object holds the logic for purchasing product items i.e. buyProduct
Varieties of EJBs • Entity bean • Model persistent resources • Shared by clients • Persistent state • Long lived • Example – a product to be purchased in a shop
Programming basics – Classes and Interfaces • Remote interface • Defines the bean’s business methods • Extends javax.ejb.EJBObject • Home interface • Defines the bean’s life cycle methods (creating, removing and finding a bean) • Extends javax.ejb.EJBHome
Programming basics – Classes and Interfaces • Bean class • Must have methods matching the signatures of the methods defined in the remote interface • Must have methods corresponding to some of the methods in the home interface • Primary key • Provides a pointer into the database • Only entity beans need a primary key
The Unseen Pieces Client EJB Server EJB home stub home interface home interface EJB home remote interface EJB Object bean class remote interface EJB object stub RMI allows the downloadable stub
Several good introduction material on the web http://java.sun.com/products/ejb/articles/multitier.html This article shows a very good example on how to use EJB to develop multi-tier application!!! The example pretty much covers every thing (Session Bean, EntityBean and Servlet). http://java.sun.com/products/ejb/faq.html The FAQs on Sun EJB web site answered many general questions regarding to EJB. http://internt.isk.kth.se/~enander/DistObj/ejb/ejbpre.htm here's a good EJB presentation