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.

Slides:



Advertisements
Similar presentations
Web Application Development
Advertisements

Internet i jego zastosowania 1 J2EE Servlets. Internet i jego zastosowania 2 Agenda Overview Servlet Interface Servlet Context Request Response Sample.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Java Servlets 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.
Java Servlets: A QuickStart for CS Educators Dawn Wilkins and Kathy Gates The University of Mississippi.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Web-based Client-Server Application Server-side programming - Servlet 1.
Servlets Replace Common Gateway Interface Scripts Extend Server Functionality Modules (software components) Like applets to browsers No GUI.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
IBM Labs in Haifa Dynamic Web programming with Servlets Gal Shachor.
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.
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.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 8 Servlets (Based on Møller and Schwartzbach,
Robinson_CIS285Winter2005 Servlets CIS January 2005 Mary Robinson.
Publishing Data on the Internet Client 1 DB Internet Client 2 Client n.
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. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Introduction to Server-Side Web Development with Servlets and JSP;
1 Servers A server is a computer that responds to requests from a client – Typical requests: provide a web page, upload or download a file, send .
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.
Java Servlets & Java Server Pages Lecture July 2013.
Servlets DBI - Representation and Management of Data on the Web.
Servlets O. De Pertat. Servlets Overview Generic Server Business logic API Java Syntax: classes extending the javax.servlet.Servlet interface or any sub-class.
@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.
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.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
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.
® IBM Software Group © 2007 IBM Corporation Servlet API (Part II)
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
K. K. Wagh Polytechnic, Nashik
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
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.
Web Computing: Servlet CS587x Lecture 10 Department of Computer Science Iowa State University.
Java Servlets References: Karen Anewalt, Mary Washington College.
Introduction to Servlets
Servlets.
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Web Programming Course
Pre-assessment Questions
Servlet API and Lifecycle
Server Side Programming: Java Servlets
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
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

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 is used to generate Dynamic HTML to return to the requesting browser

The Servlet Model BROWSER Java Enabled Webserver Servlet JVMJVM HTTP Get or Post HTML Data Base

Invoking a servlet tag –webserver must be enabled for server side embeds “action” attribute of tag –can be GET or POST (HTTP 1.0) –can also be “PUT” (HTTP 1.1)

Servlets Provide Protocol independent and platform independent server side components A Common API (Servlet API) Dynamic loading either locally or over the network Security (servlet security model) More safe than CGI scripts –runs as thread not as child process

Life cycle Once invoked a servlet has a life cycle that is supported by a set of life cycle methods that are automatically run by the webserver –init() - run when initially loaded –service() - for performing the servlets service –destroy() - for destroying the servlet object –doGet() - only for HTTP servlets and is used for processing HTTP GET requests –doPost() - only for HTTP servlets and is used for processing HTTP POST requests

Servlet Interface All servlets must implement the Servlet interface Methods: –init() –service() –destroy() –getServletConfig() –getServletInfo()

ServletConfig Interface Implemented by network services to pass configuration info to a servlet when it is first loaded Methods: –getInitParameter(String name) - returns a String value of the requested parameter –getInitParameterNames() - returns an enumeration of the names of the initialization parameters –getServletContext() - returns a ServerContext object that contains the servlet’s context

ServletContext Interface Implemented by network services, gives servlets access to environmental information and allows logging of events. Methods: –getServlet() - returns an initialized and ready to run Servlet object. –getServlets() - returns an enumeration of all of the Servlet objects in this server that are in the same name space (always includes the servlet itself) –getServerInfo() - returns info about the network service the Servlet is running under –getAttribute(String name) - returns the value of the named attribute –getRealPath(String name) - returns the actual path of the named virtual path –getMimeType(String file) - returns mime type of the named file –log(String msg) - writes msg into the servlet log file

ServletRequest Interface Provides means to get information from the HTTP request header Methods: –getProtocol() –getScheme() –getParameterNames() –getParameter() –getParameterValues() –getAttribute() –getContentLength() –getContentType() –getInputStream() –getRemoteAddr() –getRemoteHost()

(more) getServerName() getServerPort() getRealPath()

ServletResponse Interface Provides means to build HTTP response header Methods: –setContentLength(int len) –setContentType(String type) –getOutputStream() - returns a ServletOutputStream for writing the response data

GenericServlet Class Abstract class that implements Servlet and ServletConfig

HttpServlet Class Abstract class that extends GenericServlet Class to provide a framework for the HTTP Protocol doGet(HttpServletRequest req, HttpServletResponse resp) doPost (HttpServletRequest req, HttpServletResponse resp) getLastModified((HttpServletRequest req)

HttpServletRequest Interface getAuthType() getHeaderNames() getHeader() getDateHeader() getIntHeader() getMethod() getQueryString() getRemoteUser() getRequestURI() getServletPath() getPathInfo() getPathTranslated()

HttpServletResponse Interface containsHeader(String name) setHeader(String name,String value) setDateHeader(String name, long value) setIntHeader(String name, int value) setStatus(int sc) setStatus(int sc, String msg) sendError(int sc) sendError(int sc, String msg) sendRedirect(String location)

HttpUtils Class getRequestURL(HttpServletRequest req) parsePostData(int ServletStream) - returns a hash table containing the name/value pairs parseQueryString(String s) - returns a hash table containing the name/value pairs