Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Advertisements

4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
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.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
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.
An introduction to Java Servlet Programming
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:
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
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.
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.
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.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
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
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
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.
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.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
@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.
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.
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.
Java Servlets Java Server Pages (JSP)
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
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
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
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.
Chapter 26 Servlets.
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
J2EE Lecture 1:Servlet and JSP
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)

Java support… The URL class Applets Servlets and JSPs…

The URL class A facility to retrieve objects from the network Decodes the object based on its extension – For example, a.gif file will generate an Image object – Can be extended to any object type that you want The objects must obviously be addressable by a URL – So far, support for “ http: ” and “ file: ” – Can be extended to support “ ftp: ” and others

URL class example URL url = new URL( InputStream in = url.openStream(); … Or: URL url = new URL( Image im = (Image) url.getContent(); An HTTP connection is made See full URL doc

Java Applets Client-side See code sample in course web site

Servlets What is a servlet? Servlets vs. CGI scripts How do they work? Example

What is a Servlet? A server-side technology Designed to overcome some limitations of existing technologies (e.g. CGI is stateless) Characteristics: – A light-weight task that can be executed as a thread – A servlet can remain in memory (a CGI script terminates when it finished) Advantages: – A servlet can service multiple client requests – Can handle multiple clients without reloading/reinitialization

Servlets…. Servlets are written in Java Can be used to: – Generate dynamic contents – Talk to databases – Work with cookies – Session management

How do they work? Receive Request Create Thread Gen Response Send Response Engine Servlet HTTP

Servlet Framework The package: javax.servlet At the top level there are three interfaces: – ServletConfig, Servlet, Serializable The servlet interface: init() service() destroy() getServiceConfig() getServiceInfo()

The GenericServlet It is an abstract class that implements Servlet public abstract GenericServlet implements Servlet, ServletConfig, Serializable { void init() abstract void service() void destroy() ServletConfig getServletConfig() String getServiceInfo() void log() }

The HttpServlet It is an abstract class that extends the GenericServlet abstract class It provides a convenient framework for handling the HTTP protocol These two classes (GenericServlet and HttpServlet) ease the task of writing servlets In the simplest case, you need to provide implementation for service()

Life cycle of a servlet Servlet is loaded into memory by server: init() Servlet processes client requests: service() Servlet is remove by server: destroy() service() is responsible for handling incoming client requests – public void service(ServiceRequest request, ServletResponse response) throws ServletException, IOException Delegates HTTP requests: doGet() & doPost()

Retrieving Parameters Use: – public String getParameter(String name) – public String[] getParameterValues(String name) So if you have a parameter name “username” in a form then to retrieve the value use: – String name = request.getParameter(“username”);

Example: Consider the following form: First Name: Last Name:

Example…. In a browser, this would look like: When “Submit Query” is clicked we have the output: – First Name := Qusay – Last Name := Mahmoud

Example The servlet: public class RequestParams extends HttpServlet { public doPost(HttpServletRequest re, HttpServletResponse response) { PrintWriter out = response.getWriter(); out.println(" test </head"); out.println(" "); String firstName = req.getParameter("firstname"); String lastName = req.getParameter("lastname"); out.println("First Name := " + firstName + " "); out.println("Last Name := " + lastName); out.println(" "); }

Servlets for WAP It is possible to use Servlets to generate WML PrintWriter out = response.getWriter(); out.println(" "); out.println("<!DOCTYPE wml …etc"); out.println(" "); out.println("Date and Time Service "); out.println("Date is: "+ new java.util.Date()); …etc

What else? Programming cookies and keeping track of sessions is easy with Servlets….APIs provided for this Explore Cookies and Session Management on your own! Something to think about: handheld devices do not support cookies, so how do you keep track of sessions??

JSP Server-side technology Enables you to embed Java code within an HTML document JSP documents have the extension.jsp When an HTTP request is received, the compilation engine converts the JSP document into a Java Servlet then the servlet will be loaded Java code is embedded between

Example // file: hello.jsp example <% String visitor = request.getParameter(“user”); if (visitor == null) visitor = “there”; %> Hello, !

Example Request parameters are passed into JSP pages using normal HTTP parameter mechanisms (using GET and POST) Therefore, for the hello.jsp: – If invoked with: it will print “Hello, World!” – If invoked with: it will print: “Hello, Mary!”

JSP for WAP <% response.setContentTyp("text/vnd.wap.wml") %> <card title="MobileDate" Date and Time Service Date is: Or you can use the PAGE directive…

What else? Additional characters may appear after the initial <%, such as !, =, to further prescribe the meaning of the tag – It is possible to create re-usable components with JSP using Java Beans Explore on your own!

HTTP Servers If you don’t have access to an HTTP server, I’d recommend that you install Jakarta-Tomcat for your personal use ….so you explore Servlets and JSP further…. –