Servlets and a little bit of Web Services Russell Beale.

Slides:



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

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
DT228/3 Web Development WWW and Client server model.
Technology Overview JAVA Servlets CS-611 S. Witherspoon.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Apache Tomcat Server Typical html Request/Response cycle
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.
Session Management A290/A590, Fall /25/2014.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
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.
Michael Brockway Application Integration Servlets l Introduction & Overview l HTTP Servlets l HTTP get Requests l HTTP post Requests l Multi-tier Applications.
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.
Server-side Technologies
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
JavaScript, Fourth Edition
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
Objectives Java Servlet Web Components
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
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,
Chapter 8 Cookies And Security JavaScript, Third Edition.
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.
Chapter 6 Server-side Programming: Java Servlets
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
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.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
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.
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.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
©SoftMooreSlide 1 Session Tracking with Servlets.
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.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
National College of Science & Information Technology.
Servlets.
Java Servlets By: Tejashri Udavant..
Java Servlets.
Chapter 26 Servlets.
Introduction to 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.
Objectives In this lesson you will learn about: Need for servlets
J2EE Lecture 1:Servlet and JSP
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Servlets and a little bit of Web Services Russell Beale

Overview In general Provide remote access to applications Servlets What are servlets How can we use them Web Services What are web services…

Objectives Learn about using servlets as one way of providing web based interfaces to databases and other applications. Learn how to create and deploy servlets using the NetBeans IDE and Tomcat server Learn about Web Services and their advantages in relation to providing web based interfaces to databases and other applications See how to create and deploy Web Services using Java, Apache Tomcat, and Apache Axis Be aware of other tools for developing, deploying, and consuming web services

Providing remote access RMICORBA DCOMWeb/HTTP Application

Access over the Web Web Application Web Server Web Application Web Browser HTTP Web Service Client HTTP Web Pages Application Interface

Servlets and Web Services Servlets providing generic access to an application, using a web interface we need to build both client and server Web Services providing generic access with a defined API allows custom interface at the client we can just build the server

Using servlets A user (1) requests some information by filling out a form containing a link to a servlet and clicking the Submit button (2). The server (3) locates the requested servlet (4). The servlet then gathers the information needed to satisfy the user's request and constructs a Web page (5) containing the information. That Web page is then displayed on the user's browser (6). (bit like CGI scripts, bit like applets) (from Sun)

Servlets Servlets are server-side resources Servlets are Java objects that act as compact web servers Can support all protocols, but are not as flexible/powerful as full servers Need to run inside a web server that supports servlets Take in requests re-directed from the web-server, write HTML back to the client

Advantages of servlets Based on Java: convenient & powerful, can talk directly to the server Efficient – lightweight Java processes, servlet code loads only once Free/very cheap

Typical uses Processing and/or storing data submitted by an HTML form. Providing dynamic content from, for example, a database query Managing state information on top of HTTP (which is stateless) e.g. an online shopping cart which manages baskets for many concurrent customers and maps every request to the right customer.

Servlets Servlets are part of J2EE All servlets implement interface javax.servlet.Servlet javax.servlet.Servlet We will be using javax.servlet.http.HttpServlet javax.servlet.http.HttpServlet

HTTP protocol 8 request methods: GET – retrieve content POST – send data, retrieve content HEAD – retrieve headers only PUT – upload content DELETE – remove content TRACE – echos the request, showing servers etc OPTIONS – returns list of supported methods CONNECT – used with SSL proxy tunnels

Lifecycle init() set up the servlet service() respond to requests, after init() destroy() shutdown the servlet

Using HttpServlet By extending HttpServlet, we only have to over-ride the methods we need to E.g., doGet(), doPost()

HelloWorld servlet Using NetBeans, we can easily create servlets under Tomcat Tomcat is a Java server that supports servlets Tomcat is bundled with NetBeans IDE HelloWorld servletservlet

POST and GET GET and POST allow information to be sent back to the webserver from a browser (or other HTTP client for that matter) Imagine that you have a form on a HTML page and clicking the "submit" button sends the data in the form back to the server, as "name=value" pairs.

HTML forms

GET… Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.

POST… A POST will send the information through a socket back to the webserver and it won't show up in the URL bar. It is stored on the request object You can send much more information to the server this way not restricted to textual data - you can send files and even binary data such as serialized Java objects

Handling GET requests GET requests call the doGet() method on your servlet Put code in that method to handle GET, or call another method to do it GET can pass in data through URL encoding

Handling POST requests POST requests call the doPost() method Put code in this method, or call another one Post data is stored on the request object PostExample.htm

Storing Data We often want to store some data about the user and their requests We can do this in 2 ways: Client-side - cookies Server-side – session data, database etc

What are cookies? HTTP protocol is stateless Browser contacts server ata URL, requests a page, provides its capabilities Server sends info to client Connection closed So to mark one visitor to track visit to site, need to store a piece of information on the client side This is the cookie HTTP header that contains text string

Two sorts Session Temporary, erased when you close browser Often used by e-commerce sites for shopping carts Persistent Written to hard drive Remain until erased or expire Used to store user preferences

Sessions Live on the server Actually built on top of cookies or URL rewritin, but you don’t have to bother with this HttpSession object Stores all the information for a session Saves you having to access the cookies yourself

Servlets and JSP Putting large amounts of HTML into servlets is a bit cumbersome JSP pages let you use Java code directly in a HTML document The Java code is then executed as a servlet at runtime