June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.

Slides:



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

1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
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.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
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 Stoney Jackson
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
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.
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.
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.
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.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
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.
Development Platforms Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Objectives Java Servlet Web Components
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
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.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
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.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
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.
Servlets Part 3. Topics Session Tracking ServletToServletCommunication-Servlet Chaining ServerSideIncludes AppletToServlet.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
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.
CSE 403 The Mythical Servlet Goals Introduce basic servlet terminology Formally introduce homework 2 Walkthrough of build & deployment Group discussion.
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.
Introduction to Servlets Allen Day. Notes This is a training NOT a presentation Please ask questions Prerequisites.
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 and the Web CSE 3330 Southern Methodist University.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
Java Servlets References: Karen Anewalt, Mary Washington College.
Introduction to Servlets
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
JDBC & Servlet CSE 4504/6504 Lab.
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Servlet.
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.
Web Search Interfaces.
J2EE Lecture 1:Servlet and JSP
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Introduction to Java Servlets
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Presentation transcript:

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 2 Today’s Lecture Trail: Servlets Lesson:overview,Cient Interaction, LifeCycle,... Additional Link ml

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 3 Servlet Architecture Client Browser Web server with servlet engine HTTP Servlet 1: send http request 2: call servlet with request info 5: send HTTP response 4: return information from servlet engine 3: perform logic

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 4 1: send HTTP request Handled by regular html tags examples: –simple –with parameters –from a form post

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 5 2: call servlet with request info Handled by the web server transparent to the developer

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 6 3: perform logic Handled by a custom java class which inherits from the Servlet class

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 7 4: return response from servlet engine Handled by the web server transparent to the developer

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 8 5: final step The browser renders the html page which is returned In this class we will only deal with HTML, but others types could be returned by servlets –I.e.: audio, images,...

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 9 Overall Servlet API base class is HttpServlet APIs to: –initialize servlets –receive http requests –retrieve information on the request –send a response to the browser –maintain session across multiple invocations (remember that HTTP is session-less)

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 10 Base Class: HttpServlet import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldServlet extends HttpServlet { … } Example from HelloWorldServlet:

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 11 Initialization of Servlet Example from PhoneServlet.java public class PhoneServlet extends HttpServlet { private Hashtable phones = new Hashtable(); private String dataFilePath = "phonelist"; // Public Methods public void init(ServletConfig conf) throws ServletException { super.init(conf); String param = getInitParameter("phonelist"); if (param != null) { dataFilePath = param; }... readFromFile(); }

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 12 HTTP GET and POST Example from PhoneServlet: public class PhoneServlet extends HttpServlet { public void init(ServletConfig conf) throws ServletException {... } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {... } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {... } doGet is called when we have HTTP GET doPost is called when we have HTTP POST

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 13 Inside doGet and doPost Three usual steps: –read request data such as input parameters –set response headers length, type –write the response data

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 14 Get Request Data and Parameters Example from PhoneServlet public void doPost (HttpServletRequest req, HttpServletResponse res)throws IOException {... String name, number, opcode; name = req.getParameter("name"); number = req.getParameter("number"); opcode = req.getParameter("opcode");... }

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 15 Set Response Headers Example from PhoneServlet: public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); String title = "Phones";... out.println(" Phone Servlet Output "); out.println(" "); out.println(" Phone Records "); out.println(" ");... )

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 16 Create response Example from PhoneServlet: public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); String title = "Phones";... out.println(" Phone Servlet Output "); out.println(" "); out.println(" Phone Records "); out.println(" ");... )

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 17 HTTP protocol is session-less –between two requests the web server does not remember the caller protocol is as follows: –browser connects to HTTP server –browser makes a request for a web resource –web server looks for the resource –web server forwards the resource to the browser –web server disconnects the browser

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 18 Sessions with Servlets The servlet engine fills-in the gap and provides a way to keep a session across multiple requests to a web server Mechanism is handled by the servlet engine “on demand” by the servlets The base class is HttpSession

June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 19 HttpSession Example from SessionServlet.java public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { HttpSession session = req.getSession(true);... //Here's the meat Integer ival = (Integer) session.getValue("sessiontest.counter"); if (ival==null) ival = new Integer(1); else ival = new Integer(ival.intValue() + 1); session.putValue("sessiontest.counter", ival);... )