Copyright, 1996 © Dale Carnegie & Associates, Inc. Presented by Hsiuling Hsieh Christine Liu.

Slides:



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

4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
 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.
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
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.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Java Server Team 8. Overview What is a Java Server? History Architecture Advantages Disadvantages Current Technologies Conclusion.
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
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.
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.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
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 Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
Jaeki Song ISQS6337 JAVA Lecture 16 Other Issues in Java.
1 Chapter 2 The Web Tier  Web Applications and Web ContainersWeb Applications and Web Containers  Dynamic Content CreationDynamic Content Creation 
Objectives Java Servlet Web Components
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.
Chapter 6 Server-side Programming: Java Servlets
1 Welcome to CSC 301 Web Programming Charles Frank.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
Servlets Server-Side Software. Objective What is a servlet? Where do servlets fit in? What can servlets do? Why are servlets better than CGI? Servlet.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
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 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
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.
Web Technologies Lecture 8 Server side web. Client Side vs. Server Side Web Client-side code executes on the end-user's computer, usually within a web.
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.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Chapter 4 Request and Response. Servlets are controlled by the container.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Servlet API and Lifecycle
Chapter 26 Servlets.
Chapter 27 WWW and HTTP.
CS122B: Projects in Databases and Web Applications Winter 2018
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
J2EE Lecture 1:Servlet and JSP
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Copyright, 1996 © Dale Carnegie & Associates, Inc. Presented by Hsiuling Hsieh Christine Liu

Introduction Java technology isn't just for programming applets which run on the client side in web browsers, or for writing Internet applications. The Servlet API brings the power of Java to your servers,too. Java technology isn't just for programming applets which run on the client side in web browsers, or for writing Internet applications. The Servlet API brings the power of Java to your servers,too. Java TM Servlet technology provides web developers with a simple, consistent mechanism for extending the functionality of a web server and for accessing existing business systems. A servlet can almost be thought of as an applet that runs on the server side -- without a face.

What is a Servlet? Servlets are protocol- and platform- independent server side components, which dynamically extend Java enabled servers. They provide a general framework for services built using the request-response paradigm.Servlets are protocol- and platform- independent server side components, which dynamically extend Java enabled servers. They provide a general framework for services built using the request-response paradigm. Servlets run inside servers. They are Java application components which are downloaded, on demand.Servlets run inside servers. They are Java application components which are downloaded, on demand.

– –Clients talking to Java Servlets in servers. Clients may range in complexity from simple HTML forms to sophisticated Java applets. Servlets will frequently use some kind of persistent storage, such as files or a database.

Servlet OOP Architecture Servlet is an instance of a Java class which implements the javax.servlet.Servlet interface (provided by the JSDK). Most servlets do this indirectly, by extending javax.servlet.http.HttpServlet or j avax.servlet.http.GenericServlet, two of javax.servlet.Servlet's standard implementations.

Hierarchy : Servlet Servlet HttpServlet|GenericServlet HttpServlet|GenericServlet MyServlet

Ways to use Servlet A simple way: A simple way: Servlet can process data which was POSTed over HTTPS using an HTML FORM, say, an order-entry, Servlet can process data which was POSTed over HTTPS using an HTML FORM, say, an order-entry, and applying the business logic used to update a company's order database.

A simple servlet

Some other uses: Since servlets handle multiple requests concurrently, the requests can be synchronized with each other to support collaborative applications such as on-line conferencing.Since servlets handle multiple requests concurrently, the requests can be synchronized with each other to support collaborative applications such as on-line conferencing. One could define a community of active agents, which share work among each other. The code for each agent would be loaded as a servlet, and the agents would pass data to each other.One could define a community of active agents, which share work among each other. The code for each agent would be loaded as a servlet, and the agents would pass data to each other. One servlet could forward requests other servers. This technique can balance load among several servers which mirror the same content.One servlet could forward requests other servers. This technique can balance load among several servers which mirror the same content.

What does Servlet look like? Servlets implement the Servlet interface, usually by extending either the generic or an HTTP-specific implementation. The simplest possible servlet defines a single method, service:Servlets implement the Servlet interface, usually by extending either the generic or an HTTP-specific implementation. The simplest possible servlet defines a single method, service: import java.servlet.*;import java.servlet.*; public class MyServlet extends GenericServlet {public class MyServlet extends GenericServlet { public void service (ServletRequest request, public void service (ServletRequest request, ServletResponse response ServletResponse response ) throws ServletException, IOException ) throws ServletException, IOException {... {... } }

(cont’d) (cont’d) The service method is provided with Request and Response parameters. These encapsulate the data sent by the client, and allowing servlets to report status including errors.The service method is provided with Request and Response parameters. These encapsulate the data sent by the client, and allowing servlets to report status including errors. Servlets normally retrieve most of their parameters through an input stream, and send their responses using an output stream:Servlets normally retrieve most of their parameters through an input stream, and send their responses using an output stream: ServletInputStream in = request.getInputStream (); ServletOutputStream out = response.getOutputStream (); These input and output streams may be used with data in whatever format is appropriate. For example, an applet and servlet might exchange data using object serialization; HTML, and numerous image formats, may also be appropriate data formats.These input and output streams may be used with data in whatever format is appropriate. For example, an applet and servlet might exchange data using object serialization; HTML, and numerous image formats, may also be appropriate data formats.

Primary Servlet methods After being loaded, three methods are involved in the lifecycle of a servlet: Servlets are activated by the server through an init call. To provide implementation of this call is to perform potentially costly (usually, I/O intensive) setup only once, rather than once per request.Servlets are activated by the server through an init call. To provide implementation of this call is to perform potentially costly (usually, I/O intensive) setup only once, rather than once per request. After initialization, servlets handle many requests. Each client request generates one service upcall. These requests may be concurrent; this allows servlets to coordinate activities among many clients.After initialization, servlets handle many requests. Each client request generates one service upcall. These requests may be concurrent; this allows servlets to coordinate activities among many clients. Requests are processed until the servlet is explicitly shut down by the web server, by calling the destroy method. The servlet's class may then become eligible for garbage collection.Requests are processed until the servlet is explicitly shut down by the web server, by calling the destroy method. The servlet's class may then become eligible for garbage collection.

HTML-Aware Servlets Many servlets will directly generate HTML formatted text, use Java formatted output classes such as java.io.PrintWriter. There is no need to use scripting languages to dynamically modify or generate HTML pages.Many servlets will directly generate HTML formatted text, use Java formatted output classes such as java.io.PrintWriter. There is no need to use scripting languages to dynamically modify or generate HTML pages.

HTTP-Specific Servlets Servlets which are being used with the HTTP protocol may support any HTTP method, including GET, POST, HEAD, and more.Servlets which are being used with the HTTP protocol may support any HTTP method, including GET, POST, HEAD, and more. They may redirect requests to other locations, and send HTTP-specific error messages.They may redirect requests to other locations, and send HTTP-specific error messages. They can get access to parameters which were passed through standard HTML forms.They can get access to parameters which were passed through standard HTML forms.

Examples: String method = request.getMethod (); // e.g. POSTString method = request.getMethod (); // e.g. POST String name = request.getParameter ("name")String name = request.getParameter ("name") String phone = request.getParameter ("phone");String phone = request.getParameter ("phone"); String card = request.getParameter ("creditcard");String card = request.getParameter ("creditcard");

Performance Feature Servlets do not require creation of a new process for each request. In most environments, many servlets run in parallel within the same process as the server. When used in such environments with HTTP, servlets provide compelling performance advantages over both the CGI approach and the Fast-CGI approach.Servlets do not require creation of a new process for each request. In most environments, many servlets run in parallel within the same process as the server. When used in such environments with HTTP, servlets provide compelling performance advantages over both the CGI approach and the Fast-CGI approach.

Performance (cont’d)

Security Features Servlets have the Java advantage: memory access violations and strong typing violations are not possibleServlets have the Java advantage: memory access violations and strong typing violations are not possible Strong security policy support. All Java environments provide a Security Manager which can be used to control whether actions such as network or file access are to be permitted.Strong security policy support. All Java environments provide a Security Manager which can be used to control whether actions such as network or file access are to be permitted.

End