Servlet API and Lifecycle

Slides:



Advertisements
Similar presentations
Internet i jego zastosowania 1 J2EE Servlets. Internet i jego zastosowania 2 Agenda Overview Servlet Interface Servlet Context Request Response Sample.
Advertisements

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.
Object-Oriented Enterprise Application Development Introduction to Servlets.
Servlets CS-328 Dick Steflik. What is a servlet A Java application run on a thread of the webserver in response to an HTTP GET or POST request. The servlet.
Servlet details Russell Beale. Servlet lifecycle The servlet container creates only one instance of each servlet Each use request handled with a separate.
/ department of mathematics and computer sciencedepartment of mathematics and computer science / architecture of information systems.
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 Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Robinson_CIS285Winter2005 Servlets CIS January 2005 Mary Robinson.
Servlets By B. Venkateswarlu M.Tech Assoc Prof IT(Dept) Newton’s Institute of Engineering By B. Venkateswarlu M.Tech Assoc Prof IT(Dept) Newton’s Institute.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Copyright, 1996 © Dale Carnegie & Associates, Inc. Presented by Hsiuling Hsieh Christine Liu.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Java Servlets & Java Server Pages Lecture July 2013.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
L.MARIA MICHAEL VISUWASAM UNIT-4
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.
Java Enterprise Edition Programming Page 1 of 9Configuring Servlets Web Application Context Name  In multiple web applications, a “context name” is used.
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 Servelets. A servlet is a server side software component, written in java that dynamically extends the functionality of a server. A servlet is a.
©SoftMooreSlide 1 Session Tracking with Servlets.
MVC for Servlets 26-Apr-17.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
April 20023CSG11 Electronic Commerce Java (2) John Wordsworth Department of Computer Science The University of Reading Room 129,
Chapter 4 Request and Response. Servlets are controlled by the container.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
JSP Implicit Objects CS 422 Dick Steflik.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Servlets.
Server Side Programming
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Java Servlets.
Pre-assessment Questions
Server Side Programming: Java Servlets
Chapter 26 Servlets.
Java Servlet Ziad A. Al-Sharif.
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 about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
MVC for Servlets 23-Feb-19.
Knowledge Byte In this section, you will learn about:
CS3220 Web and Internet Programming Introduction to Java Servlets
J2EE Lecture 1:Servlet and JSP
Introduction to Java Servlets
MVC for Servlets 29-Apr-19.
MVC for Servlets 5-Jul-19.
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Servlet API and Lifecycle Unit III - Chapter 2 Servlet API and Lifecycle

Introduction Java provides a servlet Application Programming interface[API] which is class library. Servlets can access the entire family of Java APIs. The java Servlet API is the class library using which request can be processed and responses can be constructed, dynamically.

Servlet API The servlet API is included into two packages: javax.servlet and javax.servlet.http. The first package is intended to be generic and the second specific to the HTTP and HTTPS protocols. Servlet are java classes that extend javax.servlet.http.HttpServlet.

javax.servlet package The javax.servlet package contains a number of classes and interfaces. This package includes classes for: Communicating with the host server and client: ServletRequest ServletResponse Communicating with the client: ServletInputStream ServletOutputStream

Servlet Interface This interface is for developing servlets. A servlet is a body of Java code that is loaded into and runs inside a servlet engine, such as a web server. It receives and responds to requests from clients. For example, a client may need information from a database; a servlet can be written that receives the request, gets and processes the data as needed by the client, and then returns it to the client. Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol. To implement this interface, you can write a generic servlet that extends javax.servlet.GenericServlet or an HTTP servlet that extends javax.servlet.http.HttpServlet .

1. Servlet is created then initialized. 2. Zero or more service calls from clients are handled 3. Servlet is destroyed then garbage collected and finalized

The following are the methods available in this interface: init() : Initializes the servlet getServletConfig() : Returns a servlet config object, which contains any initialization parameters and startup configuration for this servlet. Service() : Carries out a single request from the client. The method implements a request and response paradigm. getServletInfo() : Returns a string containing information about the servlet, such as its author, version, and copyright. destroy() : Cleans up whatever resources are being held (e.g., memory, file handles, threads) and makes sure that any persistent state is synchronized with the servlet's current in-memory state.

servletContext interface An object of ServletContext is created by the web container at time of deploying the project. This object can be used to get configuration information from web.xml file. There is only one ServletContext object per web application. web.xml For a Java servlet to be accessible from a browser, you must tell the servlet container what servlets to deploy, and what URL's to map the servlets to. This is done in the web.xml file of your Java web application.

Advantage of ServletContext Easy to maintain if any information is shared to all the servlet, it is better to make it available for all the servlet. We provide this information from the web.xml file, so if the information is changed, we don't need to modify the servlet. Thus it removes maintenance problem.

There can be a lot of usage of ServletContext object There can be a lot of usage of ServletContext object. Some of them are as follows: The object of ServletContext provides an interface between the container and servlet. The ServletContext object can be used to get configuration information from the web.xml file. The ServletContext object can be used to set, get or remove attribute from the web.xml file. The ServletContext object can be used to provide inter-application communication.

The following are the methods available in this interface: getServerInfo() getInitParameter () getInitParameterNames() setInitParameter() getAttribute() getAttributeNames() setAttribute() removeAttribute addServlet() Etc…..

Example of getServletContext() method ServletContext application=getServletContext();

servletConfig interface