Objectives In this lesson you will learn about: Need for servlets

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Advertisements

Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
Servlets and a little bit of Web Services Russell Beale.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
Definition Servlet: Servlet is a java class which extends the functionality of web server by dynamically generating web pages. Web server: It is a server.
Session-02.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Java Servlets CS-422. Application Mapping Your servlet application will be mapped to a directory structure: –“myapp” maps to some directory C:/docs/apps/myapp.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Objectives Java Servlet Web Components
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Introduction to J2EE Architecture Portions by Kunal Mehta.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
Servlets.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Java Servlets Java Server Pages (JSP)
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Servlets.
Server Side Programming
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
Java Servlets.
Pre assessment Questions
Sri Vatsav Konreddy CIS 764 FALL 2007
Pre-assessment Questions
Introduction to J2EE Architecture
Servlet API and Lifecycle
MSIS 655 Advanced Business Applications Programming
Chapter 26 Servlets.
J2EE Application Development
CS122B: Projects in Databases and Web Applications Winter 2018
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Spring 2018
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Objectives In this lesson, you will learn to:
J2EE Lecture 1:Servlet and JSP
Enterprise Java Beans.
Pre-assessment Questions
Introduction to Servlet
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Objectives In this lesson you will learn about: Need for servlets Classes and interfaces to develop servlets Servlet life cycle methods Steps to develop and deploy a servlet J2EE Web Components

Servlet Concepts Java Servlets are: Server side programs written in Java. Deployed in a Web container of an application server which provides a runtime environment for servlets. Executed when the J2EE application server receives a client request that is passed to the Web container, which in turn invokes the servlet. J2EE Web Components

Servlet Concepts (Contd.). Features of Java Servlets are: Security: Inherits the security feature provided by the Web container. Session Management: Maintains the identity and state of an end user across multiple requests. Instance persistence: Enhances the performance of the server by preventing frequent disk access. J2EE Web Components

The Servlet Class Hierarchy and Life Cycle Methods The Servlet Class Hierarchy consists of two top level interfaces which are implemented by the GenericServlet class: javax.servlet.Servlet javax.servlet.ServletConfig The GenericServlet class is extended by the HttpServlet class which in turn is extended by a user defined class. J2EE Web Components

The Servlet Class Hierarchy and Life Cycle Methods (Contd.) The Servlet Life Cycle includes: Initialization of servlet instance using the init() method. Servicing a client request using the service() method. Destroying a servlet instance using the destroy() method. J2EE Web Components

The Servlet Class Hierarchy and Life Cycle Methods (Contd.) The sequence in which the Web container calls the life cycle methods of a servlet are: The Web container loads the servlet class and creates one or more instances of the servlet class. The Web container invokes the init() method of the servlet instance during initialization of the servlet. The init() method is invoked only once in the servlet life cycle. The Web container invokes the service() method to allow a servlet to process a client request. J2EE Web Components

The Servlet Class Hierarchy and Life Cycle Methods (Contd.) 4. The service() method processes the request and returns the response back to the Web container. 5. The servlet then waits to receive and process subsequent requests as explained in steps 3 and 4. 6. The Web container calls the destroy() method before removing the servlet instance from the service. The destroy() method is also invoked only once in a servlet life cycle. J2EE Web Components

Creating the Servlet r Creating the Servlet involves: Coding the Servlet: Includes reading and processing a client request and sending the response back to the client. Compiling the Servlet: Include the j2ee.jar file in the classpath and compile the servlet to generate a .class file. J2EE Web Components r

Creating the Servlet (Contd.) Creating the Servlet involves (Contd.): Packaging the Servlet: Creates the deployment descriptor that contains the configuration information about the Web application in which it resides. It packages the servlet in a WAR file and deploy it in the server using the deploytool. Accessing the Servlet: Calls the servlet from the client browser by typing the servlet’s URL in the address bar of the browser. J2EE Web Components

Demonstration-Implementing a Servlet Application Problem Statement Smart Software Developers wants to develop a Web application that will use servlets to display employee information stored in the Employee_Master table. The application needs to have a user interface in which a user can specify an employee id to view the data of the employee. The interface should also display the number of times this Web site has been visited. J2EE Web Components

Demonstration-Implementing a Servlet Application(Contd.) Solution Create a user interface using HTML. Code and compile the servlet. Package the servlet into a J2EE application. Deploy the J2EE Application. Test the servlet by invoking it from the browser. J2EE Web Components

Summary In this lesson, you learned: Servlet is a server-side program written in Java that dynamically extends the functionality of an application server. J2EE 1.4 application server deploys J2EE Web components inside a Web container, which provides runtime environment for servlets. The classes and interfaces, which are used to develop a servlet, are packaged in the javax.servlet and javax.servlet.http packages of the servlet API. A servlet can be developed by extending the HttpServlet class, if the client is using an HTTP protocol for sending the request to the servlet. The javax.servlet.Servlet interface defines methods that are used to manage the servlet life cycle. J2EE Web Components

Summary (Contd.) The javax.servlet.ServletConfig interface is implemented by a Web container to pass configuration information to a servlet. The javax.servlet.Servlet interface defines the life cycle methods of servlets, such as init (), service (), and destroy (). The init() method of the servlet instance is invoked during initialization of the servlet by the Web container. The Web container invokes the service() method of the servlet instance when the Web container receives a client request. The Web container calls the destroy() method before removing a servlet instance from service. J2EE Web Components

Summary (Contd.) The tasks involved in creating and running a servlet are: Code and compile the servlet Package the servlet into a J2EE application Deploy the J2EE Application Access the servlet from a browser An HttpServletRequest object represents a request sent by a client using HTTP. An HttpServletResponse object represents a response sent by a servlet instance to a client using HTTP. J2EE Web Components