Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
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.
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.
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.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
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.
Servlets Replace Common Gateway Interface Scripts Extend Server Functionality Modules (software components) Like applets to browsers No GUI.
13-Jul-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.
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 Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
SERVLET Ch-6. Introduction Web development is all about communication. In this case, communication between 2 parties, over the HTTP protocol: The Server.
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. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Michael Brockway Application Integration Servlets l Introduction & Overview l HTTP Servlets l HTTP get Requests l HTTP post Requests l Multi-tier Applications.
Chapter 10 Servlets and Java Server Pages. A servlet is a Java class designed to be run in the context of a special servlet container An instance of the.
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.
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,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Servlets O. De Pertat. Servlets Overview Generic Server Business logic API Java Syntax: classes extending the javax.servlet.Servlet interface or any sub-class.
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.
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.
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.
SERVLET THETOPPERSWAY.COM
Chapter 4 Request and Response. Servlets are controlled by the container.
Java Servlets References: Karen Anewalt, Mary Washington College.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Servlets.
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Chapter 6 Server-side Programming: Java Servlets
Pre-assessment Questions
Servlet API and Lifecycle
Java Servlets 9/18/2018.
Distributed Computing, M. L. Liu
Java Servlets 9/21/2018.
Chapter 26 Servlets.
Distributed Computing, M. L. Liu
CS122B: Projects in Databases and Web Applications Winter 2018
Servlets.
CS122B: Projects in Databases and Web Applications Spring 2018
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
CS3220 Web and Internet Programming Handling HTTP Requests
Servlets 7-Apr-19.
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet javax.servlet.http.HttpServlet

Generic Servlet & HTTP Servlet Client request Server service ( ) response HTTPServlet Browser request doGet ( ) HTTP Server service ( ) response doPost ( )

Interface javax.servlet.Servlet The Servlet interface defines methods to initialize a servlet to receive and respond to client requests to destroy a servlet and its resources to get any startup information to return basic information about itself, such as its author, version and copyright. Developers need to directly implement this interface only if their servlets cannot (or choose not to) inherit from GenericServlet or HttpServlet. Life Cycle Methods

GenericServlet - Methods void init(ServletConfig config) Initializes the servlet. void service(ServletRequest req, ServletResponse res) Carries out a single request from the client. void 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. ServletConfig getServletConfig() Returns a servlet config object, which contains any initialization parameters and startup configuration for this servlet. String getServletInfo() Returns a string containing information about the servlet, such as its author, version, and copyright.

HTTPServlet A general servlet knows nothing about the HyperText Transfer Protocol (HTTP), which is the major protocol used for Internet. A special kind of servlet, HTTPServlet, is needed to handle requests from HTTP clients such as web browsers. HTTPServlet is included in the package javax.servlet.http as a subclass of GenericServlet.

Hypertext Transfer Protocol Hypertext Transfer Protocol (HTTP) is the network protocol that underpins the World Wide Web. For example: a) when a user enters a URL in a Web browser, the browser issues an HTTP GET request to the Web server b) the HTTP GET method is used by the server to retrieve a document c) the Web server then responds with the requested HTML document

HTTP Methods Not useful for Web applications: PUT - place documents directly to a server TRACE - debugging DELETE - remove documents from a server OPTIONS - ask a server what methods and other options the server supports for the requested resource HEAD - requests the header of a response Useful for Web applications: GET - request information from a server POST - sends an unlimited amount of information over a socket connection as part of the HTTP request

Get Versus Post GET request : POST request : provides a limited amount of information in the form of a query string which is normally up to 255 characters visible in a URL must only be used to execute queries in a Web application POST request : sends an unlimited amount of information does not appear as part of a URL

HttpServlet

HTTPServlet A general servlet knows nothing about the HyperText Transfer Protocol (HTTP), which is the major protocol used for Internet. A special kind of servlet, HTTPServlet, is needed to handle requests from HTTP clients such as web browsers. HTTPServlet is included in the package javax.servlet.http as a subclass of GenericServlet.

HttpServlet - Methods void doGet (HttpServletRequest request, HttpServletResponse response) handles GET requests void doPost (HttpServletRequest request, handles POST requests void doPut (HttpServletRequest request, handles PUT requests void doDelete (HttpServletRequest request, handles DELETE requests

Servlet Request Objects provides client request information to a servlet. the servlet container creates a servlet request object and passes it as an argument to the servlet's service method. the ServletRequest interface define methods to retrieve data sent as client request: parameter name and values attributes input stream HTTPServletRequest extends the ServletRequest interface to provide request information for HTTP servlets

HttpServletRequest - Methods Enumeration getParameterNames() an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters java.lang.String[] getParameterValues (java.lang.String name) Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. java.lang.String getParameter (java.lang.String name) Returns the value of a request parameter as a String, or null if the parameter does not exist.

HttpServletRequest - Methods Cookie[] getCookies() Returns an array containing all of the Cookie objects the client sent with this request. java.lang.String getMethod() Returns the name of the HTTP method with which\thi request was made, for example, GET, POST, or PUT. getQueryString() Returns the query string that is contained in the request URL after the path. HttpSession getSession() Returns the current session associated with this request, or if the request does not have a session, creates one.

Servlet Response Objects Defines an object to assist a servlet in sending a response to the client. The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method.

HttpServletResponse - Methods java.io.PrintWriter getWriter() Returns a PrintWriter object that can send character text to the client void setContentType (java.lang.String type) Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example, text/html; charset=ISO-8859-4 int getBufferSize() Returns the actual buffer size used for the response

DEMO