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.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
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.
10-Jun-15 Servlets. 2 Servers A server is a computer that responds to requests from a client Typical requests: provide a web page, upload or download.
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.
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
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.
Servlets Life Cycle. The Servlet Life Cycle A servlet life cycle can be defined as the entire process from its creation till the destruction. The following.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
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.
Robinson_CIS285Winter2005 Servlets CIS January 2005 Mary Robinson.
Java Servelets. What Is a Servlet? A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
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.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Chapter 5 HTTP Request Headers. Content 1.Request headers 2.Reading Request Headers 3.Making a Table of All Request Headers 4.Sending Compressed Web Pages.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
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.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 Servlets Modified slides from Dr.Sagiv. 2 Introduction.
1 Handling the Client Request: HTTP Request Headers.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
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.
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.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
SERVLET THETOPPERSWAY.COM
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Chapter 4 Request and Response. Servlets are controlled by the container.
Introduction to Servlets
Servlets.
Server Side Programming
Servlet Fudamentals.
CSE 403: Servlet Technology
HTTP request message two types of HTTP messages: request, response
Chapter 26 Servlets.
Servlets.
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
J2EE Lecture 1:Servlet and JSP
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Introduction to Servlet
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

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 side technology which handles client request and give appropriate response to original client. Web browser: It is a client side technology which knows how to connect with web server on internet and how to request a page.

CGI(Common Gateway Interface) clientserverCGI DB request response request response process response

servlet client servlet DB request response request response server

Servlet Basic Servlet is a java class which extends the functionality of web server by dynamically generating web pages. A servlet is a java programming language class that is used to extend the capabilities of server that host application accessed by means of a request. Servlet can respond to any type of request, they are commonly used to extend the applications hosted by web server. A runtime environment known as a servlet container manages servlet loading and unloading and works with the web server to direct requests to servlets and to send output back to web clients. javax.servlet javax.servlet.http Packages provide interface and classes for writing servlets.

Architecture of servlet The javax.servlet package provides interfaces and classes for writing servlets. The architecture of the package is described below: Servlet GenericServlet HttpServlet MyServlet

Javax.Servlet  This package contains classes and interfaces not specific to any particular protocol.  These classes define the relationship between a servlet and the runtime environment provided by the servlet container.

Javax.servlet.GenericServlet  A base class for servlets that do not use HTTP protocol-specific features.  GenericServlet implements the basic features of all servlets, including initialization, request handling and termination.

Javax.servlet.http.HttpServlet  Abstract base class  Operate in an HTTP environment  HttpServlet provides specific method GET POST PUT DELETE HEAD OPTIONS TRACE request  HttpServlet override doGet(), doPost().

MyServlet MyServlet class is our own java class in that class we can write our code of program.

LifeCycle of servlet The servlet engine does the following: Loads a servlet when it is first requested. Calls the servlet’s init() method. Handles any number of requests by calling the servlet’s service() method. When shutting down, calls the destroy() method of each active servlet.

init() Syntax: public void init(ServletConfig config)throws ServletException When reqest for a servlet is received by the servlet engine, it checks to see if the servlet is already loaded. If not, the servlet engine uses a class loader to get the particular servlet class required, and then invokes its constructor to get an instance of the servlet. After the servlet is loaded, but before it services any requests, the servlet engine calls an init method. This method is called only once just before the servlet place into service.

service() Syntax: Public void service(ServletRequest req,ServletResponse res) After the init() complete successfully the servlet is able to accept request. By default, only single instance of the servlet is created, and the servlet container dispatches each request.

doGet(),doPost() Syntax: Pubic doGet/doPost(HttpServletRequest req, HttpServeltResponse res) GET requests are handled by doGet(). POST requests are handled by doPost().

Destroy() Syntax: Public void destroy() The servlet specification allows a servlet container to unload a servlet at any time. This may be done to conserve system resources or in preparation for servlet container shutdown. Release any resources allocated during init().

First Example of GenericServlet import java.io.*; import javax.servlet.*; public class SimpleServlet extends GenericServlet { public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.println(" Example of generic servlet "); out.close(); }

Servlet Life Cycle Example servlet Life cycle Example

Reading Request Headers(1) Reading headers is straightforward; just call the getHeader method of HttpServletRequest with the name of the header. This call returns a String if the specified header was supplied in the current request, null otherwise. getMethod() The getMethod method returns the main request method (normally, GET or POST, but methods like HEAD, PUT, and DELETE are possible).

Reading Request Headers(2) getRequestURI() The getRequestURI method returns the part of the URL that comes after the host and port but before the form data. For example, for a URL of getRequestURI would return "/servlet/search.BookSearch". getQueryString() The getQueryString method returns the form data. For example, with getQueryString would return "subject=jsp".

Reading Request Headers(3) getProtocol() The getProtocol method returns the third part of the request line, which is generally HTTP/1.0 or HTTP/1.1. getHeaders() In most cases, each header name appears only once in the request. Occasionally, however, a header can appear multiple times, with each occurrence listing a separate value. Accept-Language is one such example. You can use getHeaders to obtain an Enumeration of the values of all occurrences of the header.

getHeaders() Accept This header specifies the MIME types that the browser or other clients can handle. Accept-Language This header specifies the client's preferred languages in case the servlet can produce results in more than one language. The value of the header should be one of the standard language codes such as en, en-us, da, etc. User-Agent This header identifies the browser or other client making the request and can be used to return different content to different types of browsers. Most Internet Explorer versions list a "Mozilla" (Netscape) version.

getHeaders() Accept-Encoding This header designates the types of encodings that the client knows how to handle. If the server receives this header, it is free to encode the page by using one of the formats specified (usually to reduce transmission time), sending the Content-Encoding response header to indicate that it has done so. Host browsers and other clients are required to specify this header, which indicates the host and port as given in the original URL. Connection This header indicates whether the client can handle persistent HTTP connections. In HTTP 1.0, a value of Keep-Alive means that persistent connections should be used.