CS320 Web and Internet Programming Generating HTTP Responses

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Advertisements

HTTP – HyperText Transfer Protocol
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
CS320 Web and Internet Programming Generating HTTP Responses
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.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
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.
® IBM Software Group © 2007 IBM Corporation Servlet API (Part II)
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Computer Networks with Internet Technology William Stallings Chapter 04 Modern Applications 4.1 Web Access - HTTP.
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.
How HTTP Works Made by Manish Kushwaha.
Building Web Apps with Servlets
Web Basics: HTML and HTTP
HTTP – An overview.
Networking CS 3470, Section 1 Sarah Diesburg
The Hypertext Transfer Protocol
How does it work ?.
1993 version of Mosaic browser.
COMP2322 Lab 2 HTTP Steven Lee Feb. 8, 2017.
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
HTTP Protocol Specification
Hypertext Transfer Protocol
Hypertext Transport Protocol
CS3220 Web and Internet Programming Generating HTTP Responses
HTTP Protocol.
Application HTTP.
Tutorial (4): HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
Uniform Resource Locators
Generating the Server Response: HTTP Status Codes
CS320 Web and Internet Programming Cookies and Session Tracking
Networking CS 3470, Section 1 Sarah Diesburg
HTTP Request Method URL Protocol Version GET /index.html HTTP/1.1
Hypertext Transfer Protocol
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
CS320 Web and Internet Programming MVC Architecture
Uniform Resource Locators (URLs)
CS3220 Web and Internet Programming Cookies and Session Tracking
Hypertext Transfer Protocol
CS 5565 Network Architecture and Protocols
Hypertext Transfer Protocol (HTTP)
William Stallings Data and Computer Communications
CS3220 Web and Internet Programming Handling HTTP Requests
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
Uniform Resource Locators

Requests and Server Response Codes
Web Server Design Week 5 Old Dominion University
CS3220 Web and Internet Programming Cookies and Session Tracking
Application Layer Part 1
Traditional Internet Applications
Chengyu Sun California State University, Los Angeles
HTTP Hypertext Transfer Protocol
Uniform Resource Locators (URLs)
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CS320 Web and Internet Programming Generating HTTP Responses Chengyu Sun California State University, Los Angeles

HTTP Response As Output Browser Application Server HTTP request HTTP response input output program

HTTP Response Example HTTP/1.1 200 OK Content-Type: text/html;charset=ISO-8859-1 Content-Length: 168 Date: Sun, 03 Oct 2004 18:26:57 GMT Server: Apache-Coyote/1.1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>Servlet Life Cycle</title></head> <body> n is 299 and m is 440 </body> </html>

HTTP Response Status line Protocol Status code Header [Message body]

Common Status Codes 200 (OK) 401 (Unauthorized) 403 (Forbidden) 404 (Not Found) 500 (Internal Server Error)

Status Codes 100 – 199: Informational. Client should respond with further action 200 – 299: Request is successful 300 – 399: Files have moved 400 – 499: Error by the client 500 – 599: Error by the server

Redirect Codes 301 (Moved Permanently) 302 (Found) 303 (See Other) GET 302 (Found) a.k.a. (Moved Temporarily) 303 (See Other) GET and POST 307 (Temporary Redirect) GET but not POST

<error-page> in web.xml Showing customized error pages for common errors, e.g. 404 Page Not Found Example: <error-page> <error-code>404</error-code> <location>/WEB-INF/404.html</location> </error-page> <error-code>403</error-code> <location>/WEB-INF/403.html</location>

Header Fields Request Response Accept Accept-Charset Accept-Encoding Accept-Language Connection Content-Length Cookies Response Content-Type Content-Encoding Content-Language Connection Content-Length Set-Cookie

More Response Header Fields Location for redirect Refresh “Push” Incremental display Content-Disposition (RFC2183) RFC2616, Section 14 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

HttpServletResponse http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html

Header Methods in HttpServletResponse addHeader(), setHeader() addIntHeader(), setIntHeader() addDateHeader(), setDateHeader() containsHeader()

More HttpServletResponse Methods setContentType( String type ) sendRedirect( String location ) Set status code to 302 Relative URL with a leading “/” is relative to the server root getWriter() For text responses, e.g. HTML pages getOutputStream() For binary responses, e.g. images

Example: Add Revisited Redirect the user back to the input form if the parameters are missing or invalid sendRedirect() does not terminate the execution of doGet() or doPost()

Example: Countdown Automatically refreshes the display every second The Refresh header

Example: Download Download an image file from the server File I/O Content type Binary response The Content-Disposition header

Summary HTTP response format Status code ranges and some common status codes Generate non-HTML responses Use of headers Writer vs. OutputStream