CS122B: Projects in Databases and Web Applications Winter 2019

Slides:



Advertisements
Similar presentations
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Advertisements

CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
M-V-C for web applications. Model for Web Applications model consists of data and system state database tables –persistent data session information –current.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Servlets and a little bit of Web Services Russell Beale.
An introduction to Java Servlet Programming
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Server-side Technologies
Applets & Servlets.
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,
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.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Chapter 6 Server-side Programming: Java Servlets
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
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.
Java Servlets and Java Server Pages Norman White Stern School of Business.
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.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Java Servlets and Java Server Pages
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Chapter 4 Request and Response. Servlets are controlled by the container.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Java Servlets References: Karen Anewalt, Mary Washington College.
Distributed Web Systems Java Servlets Lecturer Department University.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Introduction Servlets and JSP
Servlets.
Server Side Programming
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
Java Servlets.
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Chapter 26 Servlets.
Java Servlet Ziad A. Al-Sharif.
CS122B: Projects in Databases and Web Applications Winter 2018
Introduction to Servlets
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.
Introduction to Servlet
Presentation transcript:

CS122B: Projects in Databases and Web Applications Winter 2019 Notes 06: Web-App Architectures Professor Chen Li Department of Computer Science

Outline Web applications: overview CGI and its variants Server Extension APIs Java servlets Comparisons

Web Applications Create dynamic content for a web page Example: keyword search on a document archive E-commerce … Example: Amazon.com Google.com

CGI CGI (Common Gateway Interface) Goal: Example: One of the first techniques for creating dynamic HTML pages Goal: Define a standard method for a server to talk with external applications Example: http://www.tigernt.com/cgi-bin/ecdict.cgi

CGI life cycle Main Process CGI-based Web Server e.g., apache Request for CGI 1 Child Process for CGI1 Request for CGI 2 Child Process for CGI2 Request for CGI 1 Child Process for CGI1

CGI Life Cycle (cont) Server receives a request for a CGI program Server creates a new process to run the CGI program Server passes information to the program: via environment variables and standard input.

Processes vs Thread Process Thread Typically independent Has considerably more state info than thread Separate address spaces Interact only through system inter-process communication (IPC) Thread Subsets of a process Multiple threads within a process share process state, memory, etc. Threads share their address space Process is very expensive from the perspective of the OS!

Problems with CGI Expensive to create a process for each request: requires time and significant server resources, limits the # of requests a server can handle concurrently Stateless: No history remembered “Memento”  A big problem for web-based development Solutions: cookies Still expensive

Problems with CGI (cont) Once the CGI program starts: It cannot interact with the web server It cannot take advantage of the server's abilities once it begins execution Reasons: the program is running in a separate process. Example, a CGI script cannot write to the server's log file.

Ways to improve cgi performance FastCGI Other solutions

FastCGI Main Process CGI-based Web Server Request for CGI 1 Single Child Process for CGI1 Request for CGI 2 Child Process for CGI2 Request for CGI 1 http://www.rebol.com/docs/fastcgi.html

FastCGI (cont) Developed by a company “Open Market” FastCGI creates a single persistent process for each FastCGI program It eliminates the need to create a new process for each request.

FastCGI: /  No need to start multiple processes for different requests for the same fastcgi program  Still needs one process for each cgi program. Thus not scalable to handle many concurrent requests  It does nothing to help the FastCGI program more closely interact with the server. Not implemented by some of the more popular servers, I.e., Microsoft's Internet Information Server.  Not very portable

Java Servlet Based Web Server Main Process Web Server JVM Request for Servlet 1 Thread Servlet1 Thread Request for Servlet 2 Thread Servlet2 Request for Servlet 1 A Servlet is a Service Unit

Life With Servlets A servlet is a service unit which runs inside a web server, extending its functionality beyond the basic GET, POST, DELETE and PUT operations.

Inside a Servlet A servlet does not have a main() method. a Java program: yes an applet: no Certain methods of a servlet are invoked by the server in the process of handling requests. Each time the server dispatches a request to a servlet, it invokes the servlet's service() method.

Servlet Package Hierarchy JAVAX Servlet GenericServlet HttpServlet Form Servlet Admin Servlet CGI Servlet Error Servlet File Servlet Image Servlet

The Servlet Interface Servlet interface { void init(ServletConfig sc) throws ServletException; void service(ServletRequest req, ServletResponse res); throws ServletException, IOException; void destroy(); }

Override the service() method GenericServlet Class http://java.sun.com/j2ee/1.4/docs/api/javax/servl et/GenericServlet.html Server GenericServlet subclass request service( ) response Override the service() method

HttpServlet Class http://java.sun.com/j2ee/1.4/docs/api/javax/servl et/http/HttpServlet.html java.lang.Object  javax.servlet.GenericServlet  javax.servlet.http.HttpServlet A function: protected  void doGet(HttpServletRequest req, HttpServletResponse resp)

Request and Response Objects They form the core objects for communication. HttpServletRequest contains all the details about the client request to the servlet. E.g., request.getParameter(”paramName”); HttpServletResponse contains all the information for replying back to the client. For e.g., the output stream.

Sharing stateful info within a session The first thread of an HTTP request keeps stateful information as key-value pairs on the heap of the server Since they are on the heap, they remains on the server even after the first thread is finished Threads of later requests can retrieve these key-value pairs from the heap

Comparisons CGI/FastCGI: Servlets: use multiple processes to handle separate programs and/or separate requests Outside the server Servlets: handled by separate threads within the web server process. Thus more efficient and scalable. can interact very closely with the server to do things that are not possible with CGI scripts.

Comparisons (cont) Java Servlets are portable: across operating systems (java) across web servers, since all major web servers support servlets. Thus, Java servlets offer a good platform for web-application development

Other techniques: JSP

ASP example Other techniques: ASP (Microsoft) http://www.w3schools.com/asp/showasp.asp?filename=demo_text http://www.w3schools.com/asp/showasp.asp?filename=demo_formatting <html> <body> <% response.write("Hello World!") %> </body> </html> The browser shows: Hello World!