Building Web Apps with Servlets

Slides:



Advertisements
Similar presentations
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.
Advertisements

Servlets Stoney Jackson
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
27-Jun-15 Directories and DDs. 2 Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages,
14-Jul-15 Tomcat. 2 The Apache Jakarta Project The Apache Jakarta Project “creates and maintains open source solutions on the Java platform for distribution.
Web programming for project students Dr Jim Briggs.
Server Side Programming Web Information Systems 2012.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Java Servlets and JSP.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
J2EE Web Fundamentals Lesson 1 Introduction and Overview
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
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.
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.
Java Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
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.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
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.
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.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
Java and the Web CSE 3330 Southern Methodist University.
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,
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.
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
Introduction to Servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Web Basics: HTML and HTTP
CS320 Web and Internet Programming Generating HTTP Responses
HTTP – An overview.
The Hypertext Transfer Protocol
How does it work ?.
Java Servlets By: Tejashri Udavant..
1993 version of Mosaic browser.
Net-centric Computing
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Application HTTP.
Uniform Resource Locators
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
CS320 Web and Internet Programming Cookies and Session Tracking
HTTP Request Method URL Protocol Version GET /index.html HTTP/1.1
Uniform Resource Locators (URLs)
CS3220 Web and Internet Programming Cookies and Session Tracking
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
CS3220 Web and Internet Programming Handling HTTP Requests
Servlets.
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
J2EE Lecture 1:Servlet and JSP
Uniform Resource Locators
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
CS3220 Web and Internet Programming Cookies and Session Tracking
Application Layer Part 1
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.
Directories and DDs 25-Apr-19.
Uniform Resource Locators (URLs)
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

Building Web Apps with Servlets http://flic.kr/p/hArj5

Why web apps? Create apps every bit as dynamic, interactive, and custom tailored as native apps Avoid deployment problems Reach people world wide http://flic.kr/p/9DTDXi

First, let’s review some basics about how the Web works Static Web Pages

The architecture of the Web Head First Servlets and JSP (2nd edition), p. 3

Typical web browser/server interaction http://flic.kr/p/9ksxQa At the very least, what must to give your browser so that it can request a web page? A URL! Head First Servlets and JSP (2nd edition), p. 4

Anatomy of a URL http://www.wickedlysmart.com:80/beeradvice/select/beer1.html Port Path Server Protocol Resource

So what do requests and responses actually look like anyway? Head First Servlets and JSP (2nd edition), p. 4

Example HTTP GET request HTTP Method Path to resource Protocol version GET /select/selectBeerTaste.jsp HTTP/1.1 Host: www.wickedlysmart.com User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X… Accept: text/xml,application/xml,application/xhtml+xml… Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Request headers

Text version of status code Example HTTP response Protocol version HTTP status code Text version of status code HTTP/1.1 200 OK Content-Type: text/html Content-Length: 397 Date: Wed, 19 Nov 2003 03:25:40 GMT Server: Apache-Coyote/1.1 Connection: close <html> … </html> Response headers Response body

Let’s see the request/response in a bit more detail… Head First Servlets and JSP (2nd edition), p. 18

Head First Servlets and JSP (2nd edition), p. 18

Dynamic Web Pages (Web Apps) Now, let’s talk about … Dynamic Web Pages (Web Apps)

Typical architecture of a web app Head First Servlets and JSP (2nd edition), p. 27

Typical architecture of a web app Head First Servlets and JSP (2nd edition), p. 27

Typical architecture of a web app Head First Servlets and JSP (2nd edition), p. 27

Typical architecture of a web app Head First Servlets and JSP (2nd edition), p. 27

But how do you pass parameters? Recall step #2… But how do you pass parameters? Head First Servlets and JSP (2nd edition), p. 27

GET requests can embed parameters in the URL Parameter list Head First Servlets and JSP (2nd edition), p. 14

Limitations of GET parameters Total characters limited (varies by server) Parameters are exposed Better not do passwords A better way to pass parameters: The HTTP POST method

Example HTTP POST request HTTP Method Path to resource Protocol version POST /select/selectBeerTaste.do HTTP/1.1 Host: www.wickedlysmart.com User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X… Accept: text/xml,application/xml,application/xhtml+xml… Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive color=dark&taste=malty Request headers Request body How do you make a POST request? HTML forms. More on that in a minute

Now, here’s how you implement web apps using … Servlets

Servlet web app architecture Java EE provides You write Head First Servlets and JSP (2nd edition), p. 39

How do you create a Java EE web app? Use Eclipse A few key steps: Create Dynamic Web project Create servlet class(es) Configure Deployment Descriptor (DD; aka web.xml) Compile, then deploy, then run Allow me to demonstrate

Some key features of a servlet import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Ch1Servlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); java.util.Date today = new java.util.Date(); out.println(“<html> “ + “<body>” + “<h1 align=center>HF\’s Chapter1 Servlet</h1>” + “<br>” + today + “</body>” + “</html>”); }

Some key features of a DD <?xml version=”1.0” encoding=”ISO-8859-1” ?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee xmlns:xsi=…> <servlet> <servlet-name>Chapter1 Servlet</servlet-name> <servlet-class>Ch1Servlet</servlet-class> </servlet> <servlet-mapping> <url-pattern>/Serv1</url-pattern> </servlet-mapping> </web-app> Name in DD Java class URL path

To make sure you got it, let’s walk through another servlet request/response

Head First Servlets and JSP (2nd edition), pp. 95–96

Head First Servlets and JSP (2nd edition), pp. 95–96

Head First Servlets and JSP (2nd edition), pp. 95–96

Head First Servlets and JSP (2nd edition), pp. 95–96

Head First Servlets and JSP (2nd edition), pp. 95–96

Head First Servlets and JSP (2nd edition), pp. 95–96

Summary Web architecture HTTP and HTML Web app architecture http://flic.kr/p/YSY3X Summary Web architecture HTTP and HTML Web app architecture Servlet web app architecture