1 / 32

J2EE Web Fundamentals Lesson 2 High-Level Overview

J2EE Web Fundamentals Lesson 2 High-Level Overview. Instructor: Dr. Segun Adekile. Outline. Objectives Course Text Book Basham, Bryan; Sierra, Kathy; Bates, Bert (2012-10-30). Head First Servlets and JSP (Kindle Location 1349). O'Reilly Media. Kindle Edition. High-Level Overview

marcin
Download Presentation

J2EE Web Fundamentals Lesson 2 High-Level Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. J2EE Web FundamentalsLesson 2High-Level Overview Instructor: Dr. Segun Adekile

  2. Outline • Objectives • Course Text Book • Basham, Bryan; Sierra, Kathy; Bates, Bert (2012-10-30). Head First Servlets and JSP (Kindle Location 1349). O'Reilly Media. Kindle Edition. • High-Level Overview • Web App Architecture

  3. Objectives

  4. Introduction and Overview • What is a Container? • What does the Container give you? • How the Container handles a request • Using the Deployment Descriptor to map URLs to servlets • The Model-View-Controller (MVC) Design Pattern • A “working” Deployment Descriptor (DD) • How J2EE fits into all this

  5. Introduction and Overview • Servlets need help. • When a request comes in, somebody has to instantiate the servlet or at least make a new thread to handle the request. Somebody has to call the servlet’s doPost() or doGet() method. And, oh yes, those methods have crucial arguments — the HTTP request and HTTP response objects. Somebody has to get the request and the response to the servlet. Somebody has to manage the life, death, and resources of the servlet. That somebody is the web Container. • In this chapter, we’ll look at how your web application runs in the Container, and we’ll take a first look at the structure of a web app using the Model View Controller (MVC) design pattern.

  6. What is a Container? • A Java Application that manages and runs the servlet. • Servlets don’t have a ‘main’ method. They are under the control of the container. • Examples: Tomcat, WAS

  7. What does the Container give you? • Communications Support • The Container provides an easy way for your servlets to talk to your web server. You don’t have to build a ServerSocket, listen on a port, create streams, etc. • Lifecycle Management • The Container controls the life and death of your servlets. It takes care of loading the class, instantiating and initializing the servlets, invoking the servlet methods, and making servlet instances eligible for garbage collection. • Multithreading Support • The Container automatically creates a new Java thread for every servlet request it receives. • Declarative Security • With a Container, you get to use an XML deployment descriptor to configure (and modify) security without having to hard-code it into your servlet (or any other) class code. • JSP Support • The container also translates JSPs into Servlets.

  8. How the Container handles a request

  9. How the Container handles a request

  10. How the Container handles a request

  11. How the Container handles a request • You’re wondering how the Container found the Servlet... • Somehow, the URL that comes in as part of the request from the client is mapped to a specific servlet on the server. • This mapping of URLs to servlets might be handled in a number of different ways, and it’s one of the most fundamental issues you’ll face as a web app developer. • The user request must map to a particular servlet, and it’s up to you to understand and (usually) configure that mapping.

  12. How the Container handles a request • A servlet can have THREE names • File path name:A servlet has a file path name, obviously, like classes/ registration/ SignUpServlet.class (a path to an actual class file). The original developer of the servlet class chose the class name (and the package name that defines part of the directory structure), and the location on the server defines the full path name.

  13. How the Container handles a request • A servlet can have THREE names • Deployment name: doesn’t have to be the same as the class or file name but can be. E.g the servlet class name (registration.SignUpServlet) or the relative path to the class file (classes/ registration/ SignUpServlet.class), but it can also be something completely different (like EnrollServlet).

  14. How the Container handles a request • A servlet can have THREE names • Public URL name: the name the client knows about. In other words, the name coded into the HTML so that when the user clicks a link that’s supposed to go to that servlet, this public URL name is sent to the server in the HTTP request.

  15. Using the Deployment Descriptor to map URLs to servlets • When you deploy your servlet into your web Container, you’ll create a fairly simple XML document called the Deployment Descriptor (DD) to tell the Container how to run your servlets and JSPs. • Although you’ll use the DD for more than just mapping names, you’ll use two XML elements to map URLs to servlets — one to map the client-known public URL name to your own internal name, and the other to map your own internal name to a fully-qualified class name.

  16. Using the Deployment Descriptor to map URLs to servlets

  17. Using the Deployment Descriptor to map URLs to servlets

  18. Using the Deployment Descriptor to map URLs to servlets

  19. Recap

  20. The Model-View-Controller (MVC) Design Pattern

  21. The Model-View-Controller (MVC) Design Pattern

  22. The Model-View-Controller (MVC) Design Pattern • He considered having just a single servlet, with a bunch of if tests, but decided that separate servlets would be more OO — each servlet should have one responsibility like the query page, the sign-up page, the search results page, etc. Each servlet will have all the business logic it needs to modify or read the database, and prints the HTML to the response stream back to the client.

  23. The Model-View-Controller (MVC) Design Pattern

  24. The Model-View-Controller (MVC) Design Pattern

  25. The Model-View-Controller (MVC) Design Pattern

  26. The Model-View-Controller (MVC) Design Pattern

  27. The Model-View-Controller (MVC) Design Pattern • With MVC the business logic is not only separate from the presentation... it doesn’t even know that there IS a presentation. • The essence of MVC is that you separate the business logic from the presentation, but put something between them so that the business logic can stand on its own as a reusable Java class, and doesn’t have to know anything about the view. • Bob was partly there, by separating out the business logic from the presentation, but his business logic still has an intimate connection to the view. In other words, he mixed the business logic into a servlet, and that means he can’t reuse his business logic for some other kind of view (like a Swing GUI or even a wireless app). His business logic is stuck in a servlet when it should

  28. The Model-View-Controller (MVC) Design Pattern

  29. The Model-View-Controller (MVC) Design Pattern

  30. A “working” Deployment Descriptor (DD)

  31. How J2EE fits into all this • The Java 2 Enterprise Edition is kind of a super-spec • J2EE incorporates other specifications, including the Servlets 2.4 spec and the JSP 2.0 spec. That’s for the web Container. • But the J2EE 1.5 spec also includes the Enterprise JavaBean 2.1 specification, for the EJB Container. In other words, the web Container is for web components (Servlets and JSPs), and the EJB Container is for business components. • A fully-compliant J2EE application server must have both a web Container and an EJB Container (plus other things including a JNDI and JMS implementation). • Tomcat is just a web Container! It is still compliant with the portions of the J2EE spec that address the web Container. Tomcat is a web Container, not a full J2EE application server, because Tomcat does not have an EJB Container. • A J2EE application server includes both a web Container AND an EJB Container. Tomcat is a web Container, but NOT a full J2EE application server. A J2EE 1.5 server includes the Servlet spec 2.4, JSP spec 2.0, and EJB spec 2.1.

  32. How J2EE fits into all this

More Related