COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.

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.
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.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
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.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
JSP Java Server Pages Reference:
1 Static Web Pages Websites on Servers (The Big Picture) –Apache Tomcat can support static web pages –Primarily intended to support servlets and JSP –Some.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Web programming for project students Dr Jim Briggs.
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. 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 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.
Introduction Servlets and JSP Celsina Bignoli
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.
INTRODUCTION TO WEB DATABASE PROGRAMMING
J2EE Web Fundamentals Lesson 1 Introduction and Overview
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Objectives Java Servlet Web Components
Functionality of a web server What does the web server do? Let a user request a resource Find the resource Return something to the user The resource can.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
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 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 & Java Server Pages Lecture July 2013.
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.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
@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.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
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.
Introduction to Servlets Allen Day. Notes This is a training NOT a presentation Please ask questions Prerequisites.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
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 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
Servlets.
Building Web Apps with Servlets
Web Development Web Servers.
Java Servlets By: Tejashri Udavant..
Chapter 27 WWW and HTTP.
J2EE Lecture 1:Servlet and JSP
Presentation transcript:

COMP 321 Week 7

Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction

What does a web server do? Receives request from client Returns response to client

What does a web client do? Sends request to server Receives response Displays response to the user

HTML and HTTP HTTP (Hypertext Transport Protocol) –Protocol web clients and servers use to communicate –Specifies format of requests and responses HTML (Hypertext Markup Language) –Format for specifying contents of a web page

HTML A Login Page A Login Page Skyler's Login Page Skyler's Login Page Name: Name: Password: Password:

HTML

HTTP Runs on top of TCP/IP Request Contains: –HTTP Method (GET, POST, etc.) –Page to access (ex. –Form Parameters Response Contains: –Status Code (ex. 200, 404, etc.) –Content-type (ex. text/html, image/jpg) –Content (ex. HTML document, picture, etc.)

HTTP Methods GET –Used to retrieve an object –Idempotent POST –Used to send data, perform an operation, etc. –Not idempotent

GET vs. POST Both can send data Reasons to use POST –GET parameters are visible in URL –GET data size is extremely limited Reasons to use GET –Parameters can be bookmarked along with URL

HTTP Requests WebServe Demo Check out eek7/J0/WebServe.java.html for more info eek7/J0/WebServe.java.html eek7/J0/WebServe.java.html

HTTP Response HTTP/ OK Set-Cookie: JSESSIONID=0AAB6C8DE415E2E5F307CF334BFCA0C1; Path=/testEL Content-Type: text/html Content-Length: 397 Date: Wed, 19 Nov :25:40 GMT Server: Apache-Coyote/1.1 Connection: close <html>...</html>

GET or POST? A user is returning a login name and password A user is requesting a new page via a hyperlink A chat room user is sending a written response A user hits the ‘Next’ button to see the next page A user hits the ‘Log out’ button on a secure banking site A user hits the ‘Back’ button on the browser A user sends a name and address from to the server A user makes a radio button selection

GET or POST? A user is returning a login name and password  POST – the login and password shouldn’t be exposed in the address bar A user is requesting a new page via a hyperlink  GET – this is the typical usage for get A chat room user is sending a written response  POST – the message could easily be too long for a GET A user hits the ‘Next’ button to see the next page  Depending on the browser, nothing is sent to the server in this case

GET or POST? A user hits the ‘Log out’ button on a secure banking site  Could be either – depends on implementation A user hits the ‘Back’ button on the browser  Could be either – the browser remembers which A user sends a name and address form to the server  This would usually be a POST A user makes a radio button selection  Nothing is sent to the server in this case

URL: Uniform Resource Locator ce/select/beer1.html ce/select/beer1.html Protocol – http Server – Port – 80 Path – /beeradvice/select Resource – beer1.html Query String – not shown ?type=...

TCP Ports Used to allow multiple servers to run on a single machine Each connection has a server name and destination port Standard ports are defined for common services:  21 – FTP  25 – SMPT  80 – HTTP  443 – HTTPS

Mapping URLs to Content A:

Mapping URLs to Content B:

Mapping URLs to Content C:

Mapping URLs to Content D:

Dynamic Content Web servers know how to serve static pages Many sites need to generate content dynamically: at the time it is requested A helper (or CGI) application communicates with the web server to generate the content

First There Was CGI… Client requests a link to a CGI URL Server launches and runs CGI program with supplied parameters Program creates web page and returns to server Server shuts down CGI program and returns response to client

CGI vs. Servlets Launching a new CGI process each time a request is made is expensive Servlets reuse the same JVM and even the same Servlet object for each request, and only create a new thread Servlets can use J2EE security, transactions, and EJBs directly

Servlets Live in a container Are called by container when specific requests arrive  doGet() called for GET requests  doPost() called for POST requests

The Servlet Container Handles all communication Manages Servlet Lifecycle Handles Multithreading Allows Declarative Security Handles JSP Support

Servlet Request Processing 1. User clicks a link that contains a Servlet URL 2. Container creates HttpServletRequest and HttpServletResponse objects 3. Container finds correct Servlet, and creates thread for request 4. Container calls doGet() or doPost() with request and response objects 5. Servlet generates dynamic page, and puts it in the response object 6. The thread completes, the server converts the response to an HTTP response, and returns it to the client

Servlet Example public class Ch2Servlet extends HttpServlet { public void doGet(HttpServletRequest request, public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter(); Date today = new Date(); Date today = new Date(); out.println( out.println( " " + " " + "HF\'s Chapter2 Servlet " + "HF\'s Chapter2 Servlet " + " " + today + " " + today + " " + " " + " "); " "); }}

Servlet Mapping Basics Public URL Name – the URL that is exposed to the browser “Secret” Deployment Name – internal name used to tie URL and File Path together File Path Name – actual location of class file on disk

Deployment Descriptor Internal Name 1 Internal Name 1 foo.Servlet1 foo.Servlet1 Internal Name 2 Internal Name 2 foo.Servlet2 foo.Servlet2 Internal Name 1 Internal Name 1 /Public1 /Public1 Internal Name 2 Internal Name 2 /Public2 /Public2 </web-app>

Case Study – GeekDates Bryan creates a dating site One Servlet per page  MainPageServlet  InputDQLServlet  DoDQLQueryServlet  etc.

Case Study – GeekDates cont’d public class DatingServlet extends HttpServlet { public void doGet(HttpServletRequest request, public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException HttpServletResponse response) throws IOException // business logic goes here // business logic goes here // (read db, write db, etc.) // (read db, write db, etc.) PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter(); // Ugly HTML strings embedded in Java go here // Ugly HTML strings embedded in Java go here }}

GeekDates 2.0 Bryan moves HTML to JSPs  Each servlet performs business logic, then redirects to JSP  JSPs contain HTML with small amounts of Java sprinkled in  JSPs only display data they’re given, and presentation is now separate from business logic

Case Study – GeekDates cont’d What if we want access GeekDates from a Swing app?  Can’t be done – business logic is entangled with Servlet-specific code  Bryan should have used the MVC (Model- View-Controller) pattern

MVC Model  Holds state  Holds business logic - contains rules for getting and updating state View  Gets state from Model (through Controller), and displays it  Sends user input to Controller Controller  Takes user input from View and sends to Model  Allows View to access Model

GeekDates 3.0 Now Bryan creates a model class for each page  InputSignupModel.java  InputSignupServlet.java  InputSignup.jsp All of the Servlets have nearly the same logic. What can we do about this?

Who’s Responsible? Task Web Server ContainerServlet Creates request & response objects Calls the service() method Starts a new thread to handle request Converts a response object to an HTTP response Knows HTTP Adds HTML to the response object Has a reference to the response objects Finds URLs in the DD Deletes the request and response Coordinates making dynamic content Manages lifecycles Name that matches in DD

Who’s Responsible? Task Web Server ContainerServlet Creates request & response objects X Calls the service() method X Starts a new thread to handle request X Converts a response object to an HTTP response x Knows HTTP x Adds HTML to the response object x Has a reference to the response objects xx Finds URLs in the DD x Deletes the request and response x Coordinates making dynamic content xx Manages lifecycles x Name that matches in DD x

J2EE J2EE is a group of specifications – Servlet, JSP, EJB, etc. A fully-compliant container must have a Servlet container and an EJB container Tomcat is a web container, not a full J2EE application server (no EJBs)

Tomcat with Eclipse Demonstration

Lab 7-1 Introduction

Progress Check Due this week:  Lab 5-2 Database Application Interfaces Due next week:  Lab 7-1 Preparing to Build Web Applications