SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.

Slides:



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

Servlets & JSPs - Sharad Ballepu.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
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 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.
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.
Servlets and a little bit of Web Services Russell Beale.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
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.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
Server Side Programming Web Information Systems 2012.
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.
CSCI 6962: Server-side Design and Programming History and Background.
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.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
J2EE Web Fundamentals Lesson 1 Introduction and Overview
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
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.
Web application architecture
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CS-4220 Dr. Mark L. Hornick1 Servlet configuration and deployment.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
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. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Website Development with PHP and MySQL Saving Data.
Chapter 6 Server-side Programming: Java Servlets
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
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
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
2007cs Servers on the Web. The World-Wide Web 2007 cs CSS JS HTML Server Browser JS CSS HTML Transfer of resources using HTTP.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
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.
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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
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.
CS-4220 Dr. Mark L. Hornick1 Single class doing too many things =Bad Code Smell.
Servlets.
Net-centric Computing
Chapter 26 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.
HTTP GET vs POST SE-2840 Dr. Mark L. Hornick.
J2EE Lecture 1:Servlet and JSP
Presentation transcript:

SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture

Recall: The interaction between web clients and servers is structured around HTTP Request and Response messages SE-2840 Dr. Mark L. Hornick2 Server is running a web server app, like Apache or Microsoft IIS.

In the simplest scenario, the Server responds to a browser GET request by returning a pre-written, static HTML file SE-2840 Dr. Mark L. Hornick3 Note: This diagram can be found in your textbook HTML file maintained on Server, returned to the Browser as the HTTP response “payload” HTTP GET request

A web server can employ a Helper App when it needs to go beyond serving static web pages SE-2840 Dr. Mark L. Hornick4 parameters CGI * programs can be written in Perl, Python, PHP, C, or – Java *Common Gateway Interface HTTP GET or POST request (may include parameters) CGI Helper app

How it works in general SE-2840 Dr. Mark L. Hornick5 Note: This diagram can be found in your textbook User enters a URL (or clicks a link) to a CGI program rather than a static page Web server “sees” that the request is for a helper program, so the server runs the helper, sending along any parameters sent from the Client. The helper app constructs the brand new (dynamic) page and sends the HTML back to the server.

How it works for Java Servlets SE-2840 Dr. Mark L. Hornick6 Note: This diagram can be found in your textbook Web server app is commonly Apache Web container app is Tomcat Servlets are run by Tomcat

What does a Container like Tomcat do? Communication Creates server-side sockets Listens for client connections Determines client HTTP request type and “decodes” HTTP headers Servlet Lifecycle management Figures out which Servlet should be used to process a specific request Handles Servlet class loading Handles Servlet instantiation/construction Handles Servlet initialization Servlet execution support Launches/manages threads that service each incoming request Handles Servlet service() method invocation Creates and passes Request and Response objects to the Servlet Supports Security Supports JSP SE-2840 Dr. Mark L. Hornick7

How Tomcat manages Servlets CS-4220 Dr. Mark L. Hornick8 Note: This diagram can be found in your textbook Called only ONCE in the servlet’s life (and must complete before Container calls service() Container calls destroy() to give the servlet a chance to clean up; like init(), destroy() is only called ONCE The methods doGet() or doPost() are executed to process requests This is where the servlet spends most of its life Web Container (Tomcat) Your servlet class no-arg ctor runs (you should NOT write a ctor; just use the compiler- supplied default.

Tomcat invokes a Servlet’s service() method, but your HTTPServlet-derived class should only override doGet() or doPost() SE-2840 Dr. Mark L. Hornick9 The service() method is given an implementation in the HTTPServlet base class, where the doGet() and doPost() methods are called. You must override these methods in your HttpServlet-derived class

A Servlet is just a Java class that implements some specific interfaces (defined by the Java Servlet Specifications) that are used by the Container SE-2840 Dr. Mark L. Hornick10 All Servlets must implement these 5 methods Abstract class. Implements most of the basic servlet methods Implements the service() method and calls doGet(), doPost() etc as appropriate

NOTE The Java classes pertaining to Servlets are not part of the standard 1.6 SE They are part of the Java EE specification Implementation of the 1.6 SE is provided in the 1.6 JDK/JRE System Library This is the library you are probably most familiar with rt.jar is the main jarfile in this library Container vendors supply the implementation of the classes that are part of the Servlet specification Tomcat comes with its own Servlet libraries servlet-api.jar implements the Servlet-related classes SE-2840 Dr. Mark L. Hornick11

SE-2840 Dr. Mark L. Hornick12 Parameters: HTML tag element " method=“post"> The opening tag – all form elements go between the opening and closing tag. The required action attribute specifies the url of where to send the form’s data. …and the name of the Web Resource that will process the form data if it is submitted The method attribute specifies which HTTP message will be used to send the data in the form to the server – default is “get” Note: See the examples on the course website

GET vs. POST scenarios SE-2840 Dr. Mark L. Hornick13 Note: This diagram can be found in your textbook

SE-2840 Dr. Mark L. Hornick 14 get specifies that a HTTP GET message should be used, which appends the form data to the end of the url / ?firstname=Arnold&last name=Ziffel get requests have a limit of 256 characters The data is plainly visible in the url (insecure!) You can bookmark a page that is the result of submitting a form Use GET only to submit small amounts of insensitive data which the server app will NOT use to modify its internal state

SE-2840 Dr. Mark L. Hornick 15 post specifies that a HTTP POST message should be used, which appends the form data to the end of the HTTP POST header There is no limit on the size of the data packet that can be sent to the server You cannot bookmark a url that was generated as a POST message, since the form data is not in the url A post request can be encrypted (using HTTPS) in order to protect sensitive data, such as a credit card numbers or passwords Use POST to send form data that Is sensitive (use encryption in that case) If the data is large (>256 bytes) Will change the state of the web application Note: Detailed explanation on pp in your text. Be sure to read it!

SE-2840 Dr. Mark L. Hornick16 These contain all kinds of useful stuff Servlet execution – Part 1 of 2

SE-2840 Dr. Mark L. Hornick 17 Note: This diagram can be found in your textbook Servlet execution – Part 2 of 2

The HTTP Request Wrapper Class SE-2840 Dr. Mark L. Hornick18 A reference to an HTTPServletRequest is created by the Container and passed to the doGet() and doPost() methods of an HTTPServlet These methods are about HTTP things like headers, sessions, and cookies

The HTTP Response Wrapper Class SE-2840 Dr. Mark L. Hornick19 A reference to an HTTPServletResponse is created by the Container and passed to the doGet() and doPost() methods of an HTTPServlet These methods are also about HTTP things like headers, sessions, and cookies