CS3220 Web and Internet Programming Handling HTTP Requests

Slides:



Advertisements
Similar presentations
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
PHP syntax basics. Personal Home Page This is a Hypertext processor It works on the server side It demands a Web-server to be installed.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Servlets and a little bit of Web Services Russell Beale.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
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.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
Web application architecture
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
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.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
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.
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.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Overview of Servlets and JSP
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
What’s Really Happening
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
CS3220 Web and Internet Programming Introduction to Java Servlets
Tiny http client and server
CS520 Web Programming Servlet and JSP Review
Servlets.
Building Web Apps with Servlets
Web Basics: HTML and HTTP
CS320 Web and Internet Programming Generating HTTP Responses
Content from Python Docs.
HTTP – An overview.
Networking CS 3470, Section 1 Sarah Diesburg
The Hypertext Transfer Protocol
How does it work ?.
1993 version of Mosaic browser.
CS520 Web Programming Servlet and JSP Review
COMP2322 Lab 2 HTTP Steven Lee Feb. 8, 2017.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Hypertext Transport Protocol
CS3220 Web and Internet Programming Generating HTTP Responses
Introduction Web Environments
HTTP Protocol.
Application HTTP.
Uniform Resource Locators
WEB API.
Chapter 26 Servlets.
CS320 Web and Internet Programming Cookies and Session Tracking
HTTP Request Method URL Protocol Version GET /index.html HTTP/1.1
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Uniform Resource Locators (URLs)
CS3220 Web and Internet Programming Cookies and Session Tracking
Hypertext Transfer Protocol
Chengyu Sun California State University, Los Angeles
HyperText Transfer Protocol
COP 4610L: Applications in the Enterprise Spring 2005
CS3220 Web and Internet Programming Introduction to Java Servlets
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
Uniform Resource Locators

CS3220 Web and Internet Programming Cookies and Session Tracking
Chengyu Sun California State University, Los Angeles
HTTP Hypertext Transfer Protocol
Uniform Resource Locators (URLs)
Presentation transcript:

CS3220 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles

HTTP Request As Input Browser Application Server program HTTP request HTTP response input output program

Examine HTTP Requests and Responses The Network tab in Developer Tools in Chrome or Firefox, or TCP/IP Monitor in Eclipse

TCP/IP Monitor in Eclipse ... request Client Server response localhost host:port Client TCP/IP Monitor Server request request response response localhost host:port

... TCP/IP Monitor in Eclipse Window  Preferences  Run/Debug  TCP/IP Monitor Example: monitor the access of http:///sun.calstatela.edu/~cysun/index.html Local Monitoring Port?? Host?? Port?? Browser URL??

HTTP Request Example http://cs.calstatela.edu:4040/foo GET /foo HTTP/1.1 Host: cs.calstatela.edu:4040 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.3) ... Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,... 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 Cookie: nxt/gateway.dll/uid=4B4CF072; SITESERVER=ID=f1675...

HTTP Request Request line Header [Message body] Method Request URI Protocol Header [Message body]

Request Methods Actions to be performed regarding the resource identified by the Request URI Browser GET POST Editor PUT DELETE Diagnosis HEAD OPTIONS TRACE

HttpServlet Methods service() GET  POST  PUT  DELETE  HEAD  OPTIONS  TRACE  doGet() doPost() doPut() doDelete() doHead() doOptions() doTrace()

Override HttpServlet Methods Default implementation returns an HTTP Bad Request error doGet(), doPost() Simply call one method from the other

Request Header Fields User-Agent Accept Accept-Charset Accept-Encoding Accept-Language Host Connection/Keep-alive Content-Length Cookie Referer RFC2616, Section 14 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

HttpServletRequest getXxx() methods http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

Example: RequestInfo Display some request information Method, request URI, request URL ... Display the IP address of the client Determine if gzip compression supported

Request Parameters Query string Form data ?param1=value1&param2=value2&... Form data

Example: Add Get two integers from request parameter and display the sum

Parameter Methods Inherited from ServletRequest String getParameter( String p ) Enumeration getParameterNames() String[] getParameterValues( String p ) Map getParameterMap()

HTML Forms <form> action – URL of the server-side program that process the submitted form data method GET: request parameters sent in query string POST: request parameters sent in message body enctype – mostly used when uploading files

Example: Guest Book My Guest Book Add Comment Edit Entry Add Comment John says: Hello! Edit | Delete Jane says: Your website looks nice. Edit | Delete Joe says: Nice to meet you. I’m from China. Edit | Delete Add Comment Add Comment Edit Entry Your name: Your name: Jane Your website looks nice. Add Save

Web Application Web application = Data + Operations Data Operations Guestbook entries, forum posts, products, customers, transactions, wiki pages, twitter message … Operations Add/create, search, display, edit, delete …

Guest Book Implementation Data GuestBookEntry List<GuestBookEntry> Operations Display Add Edit Delete

GuestBook – Display Initialize data storage in application scope Pre-create some data Generate HTML

GuestBook – Add Handling web forms usually involves two operations Display the form  doGet() Process the submission  doPost() response.sendRedirect()

GuestBook – Edit Embed an identifier of the data to be edited in generated hyperlink or form (using hidden form field)

GuestBook – Delete Use a unique and immutable identifier instead of array index

Summary HTTP Request Important classes Request line and header fields Query string Form data Important classes HttpServletRequest and its superclass ServletRequest Web application = Data + Operations