CSC 2720 Building Web Applications Servlet – Getting and Setting HTTP Headers.

Slides:



Advertisements
Similar presentations
HTTP Requests & Responses1 Servlets: HTTP Request Header Contents and Responses.
Advertisements

HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
HTTP – HyperText Transfer Protocol
1 HTTP and some other odds and ends Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 9 Application Layer, HTTP Professor Rick Han University of Colorado at Boulder
CS320 Web and Internet Programming Generating HTTP Responses
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
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.
How the web works: HTTP and CGI explained
The Information School of the University of Washington Oct university of washington1 Hypertext Markup Language INFO/CSE 100, Fall 2006 Fluency.
1 Web Search Interfaces. 2 Web Search Interface Web search engines of course need a web-based interface. Search page must accept a query string and submit.
1 CS6320 – Servlet Request and Response L. Grewe.
Web programming for project students Dr Jim Briggs.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
PL-IV- Group A HTTP Request & Response Header
Robinson_CIS285Winter2005 Servlets CIS January 2005 Mary Robinson.
Network Protocols: Design and Analysis Polly Huang EE NTU
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
Web Server Design Week 5 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/10/10.
COMP3016 Web Technologies Introduction and Discussion What is the Web?
Java Technology and Applications
Krerk Piromsopa. Web Caching Krerk Piromsopa. Department of Computer Engineering. Chulalongkorn University.
HTTP Protocol Specification
Web Caching: Replication on the World Wide Web Jonathan Bulava CSC8530 – Distributed Systems Dr. Paul Schragger.
Chapter 1 © 2003 by Addison-Wesley, Inc A Brief Intro to the Internet - Origins - ARPAnet - late 1960s and early 1970s - Funded by DoD - Purpose:
HTTP Reading: Section and COS 461: Computer Networks Spring
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
1 Lecture #7-8 HTTP – HyperText Transfer Protocol HAIT Summer 2005 Shimrit Tzur-David.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
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.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
Generating the Server Response: HTTP Response Headers.
WWW, HTTP, GET, POST, Cookies Svetlin Nakov Telerik Corporation
Chapter 5 HTTP Request Headers. Content 1.Request headers 2.Reading Request Headers 3.Making a Table of All Request Headers 4.Sending Compressed Web Pages.
Slides © Marty Hall, book © Sun Microsystems Press 1 Generating the HTTP Response Core Servlets & JSP book:
1 Introductory material. This module illustrates the interactions of the protocols of the TCP/IP protocol suite with the help of an example. The example.
Hui Zhang, Fall Computer Networking Web, HTTP, Caching.
World Wide Web (WWW) A Distributed Document- Based System Group E Ricky Tong (D-A0-1611) Eddy Leong (D-A0-1623) Dick Lei (D-A0-1658)
Proxy Lab Recitation I Monday Nov 20, 2006.
Web Server Design Week 8 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/3/10.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
CSE 524: Lecture 4 Application layer protocols. Administrative ● Reading assignment Chapter 2 ● Mid-term exam may be delayed to 11/2/2004 – Mostly on.
1 Handling the Client Request: HTTP Request Headers.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
HTTP How the Internet servers and clients communicate.
Web Server Design Week 7 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/24/10.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
SKT-SSU IT Training Center Servlet and JSP. Chapter Seven: Generating the Server Response: HTTP Response Headers.
® IBM Software Group © 2007 IBM Corporation Servlet API (Part II)
1 10/19/05CS360 Windows Programming ASP.NET. 2 10/19/05CS360 Windows Programming ASP.NET  ASP.NET works on top of the HTTP protocol  Takes advantage.
Servlets 4 Lec 30 Web Design and Development. Looking Back… Response Redirection  Sending a standard redirect  Sending a redirect to an error page Request.
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
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
LURP Details. LURP Lab Details  1.Given a GET … call a proxy CGI script in the same way you would for a normal CGI request  2.This UDP perl.
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
WEB1P webarch1 Web architecture Dr Jim Briggs. WEB1P webarch2 What is the web? Distributed system Client-server system Characteristics of clients and.
DEV336. demo HTTP Packet Trace GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible;
INTRODUCTION Dr Mohd Soperi Mohd Zahid Semester /16.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Web Server Design Week 6 Old Dominion University Department of Computer Science CS 495/595 Spring 2006 Michael L. Nelson 2/13/06.
HTTP – An overview.
Pre-assessment Questions
IE.
HTTP Protocol.
Hypertext Transfer Protocol
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
CSCI-351 Data communication and Networks
Presentation transcript:

CSC 2720 Building Web Applications Servlet – Getting and Setting HTTP Headers

Outline  What kinds of data are embedded in the HTTP request/response headers?  How useful could these data be?  What can we achieve by setting HTTP response header?  Java APIs for getting headers from HTTP request  Java APIs for setting HTTP response headers

Introduction  The headers in a HTTP request/response define various characteristics of the data that is requested or the data that has been provided. HTTP/ OK Date: Mon, 23 May :38:34 GMT Server: Apache/ (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan :11:55 GMT Etag: "3f80f-1b6-3e1cb03b" Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8 Body of the contents goes here … The header section of a HTTP response

HTTP Request Headers  You can find out more about your client.  For examples  accept, accept-encoding, accept-language, accept-charset : Content types, compression schemes, languages, and character sets that the client's browser accepts.  user-agent : Info about the client's browser and operating system  referer : The URL of the webpage that "brings" the client to the requested page  cookie : Cookies

Methods for obtaining HTTP Header Fields  Through HttpServletRequest object (request)HttpServletRequest  java.util.Enumeration getHeaderNames() Get all header names  String getHeader(String name)  long getDateHeader(String name)  int getIntHeader(String name)  Get the value of a specified header as a string / date / integer  java.util.Enumeration getHeaders(String name) Get the values of a specified header as an enumeration of strings  Cookie[] getCookies() Get all cookies

Header name Header value(s) <% Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String)headerNames.nextElement(); Enumeration values = request.getHeaders((String)name); out.println(" " + name + " "); while (values.hasMoreElements()) { out.println(values.nextElement()); // A header name may appear multiple times in the // header if it has multiple values. In such case, // we separate the values by an empty line. if (values.hasMoreElements()) out.println(" "); } out.println(" "); } %> (Part of a JSP file): Dumping all header fields in a HTTP request

Header name Header value(s) accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x- shockwave-flash, application/vnd.ms-excel, application/vnd.ms- powerpoint, application/msword, application/x-silverlight, */* refererhttp://localhost:8084/csc2720/ accept- language en-us ua-cpux86 accept- encoding gzip, deflate user-agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;.NET CLR ;.NET CLR ) hostlocalhost:8084 connectionKeep-Alive cookieJSESSIONID=E4BEE528F568A68443E26230BDF54767 Sample output produced by the previous segment of JSP code.

Examples of HTTP 1.1 Response Headers  Cache-Control  Tells all caching mechanisms from server to client whether they may cache this object.  To tells a client not to cache the requested resource, set the its value to no-cache.  Content-Language  The language the content is in  Content-Type  The MIME type of the content being returned  Use setContentType to set this header

Examples of HTTP 1.1 Response Headers  Expires  The time at which document should be considered as out- of-date  Last-Modified  The time in which the requested resource was last modified.  Location  To redirect the client's browser to a new URL  Use sendRedirect to set this value  Set-Cookie  The cookies that browser should remember.  Use addCookie to add cookies.

Methods for setting HTTP Header  Through HttpServletResponse object (response)HttpServletResponse  void setHeader(String name, String value)  void setDateHeader(String name, long value)  void setIntHeader(String name, int value) Set the value of a specific header as string / date / integer.  void addHeader(String name, String value)  void addDateHeader(String name, long value)  void addIntHeader(String name, int value) Add additional values instead of replacing the existing one for a specific header as string / date / integer.  boolean containHeader(String name) Returns true if the named header has already been set.

Methods for setting Commonly Used Headers  Through HttpServletResponse object (response)HttpServletResponse  void setContentType(String mime) Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example, response.setContentType( "text/html; charset=ISO ");  void addCookie(Cookie cookie) Adds the specified cookie to the response.  void sendRedirect(String url) Request the client to load the specified URL.

References  Wiki: List of HTTP headers   HTTP/1.1: Header Field Definitions 