CS3220 Web and Internet Programming Cookies and Session Tracking

Slides:



Advertisements
Similar presentations
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
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.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
CS320 Web and Internet Programming Generating HTTP Responses
Servlet Session Tracking. 2 Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information: Information.
Servlet Session Tracking II Session API All material and examples are from
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.
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Session tracking There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on- line.
Session Tracking - 2 Lec 32. Last Lecture Review  Session Tracking – why?  Need to store state – typical solutions Cookies – already learned URL Rewriting.
Web Application Development * These slides have been adapted and modified from CoreServlets course material (Marty Hall) and LUMS cs391 (Umair Javed).
Chapter 6 Server-side Programming: Java Servlets
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Web Database Programming Week 7 Session Management & Authentication.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
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.
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
©SoftMooreSlide 1 Session Tracking with Servlets.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Session Tracking Parts of this presentation was provided by SSE.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
Net-centric Computing Servlets & JSP. Lecture Outline  Tracking Sessions  Cookies  Examples  JSP  Differences between JSP and Servlets  JSP Constructs.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
File Uploads and Cookies Pat Morin COMP Outline File upload Cookies.
CS320 Web and Internet Programming Handling HTTP Requests Chengyu Sun California State University, Los Angeles.
Research of Web Real-Time Communication Based on WebSocket
Cookies Tutorial Cavisson Systems Inc..
Building Web Apps with 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 ?.
Servlet Sessions and Cookies
1993 version of Mosaic browser.
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
Java Servlets.
CS3220 Web and Internet Programming Generating HTTP Responses
Chapter 6 Server-side Programming: Java Servlets
Client / Session Identification Cookies
Introduction Web Environments
HTTP Protocol.
Sessions.
Uniform Resource Locators
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
Servlet Session Tracking
Client / Session Identification Cookies
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)
Hypertext Transfer Protocol
Session Tracking Techniques
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information.
CS3220 Web and Internet Programming Handling HTTP Requests
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
Uniform Resource Locators
PHP State.
CS3220 Web and Internet Programming Cookies and Session Tracking
CS5220 Advanced Topics in Web Programming Secure REST API
Application Layer Part 1
Uniform Resource Locators (URLs)
CSCI-351 Data communication and Networks
Servlet Session Tracking: Session API
[Based in part on SWE 432 and SWE 632 materials by Jeff Offutt, GMU]
Presentation transcript:

CS3220 Web and Internet Programming Cookies and Session Tracking Chengyu Sun California State University, Los Angeles

Session Tracking The Need The Difficulty The Trick? shopping cart, personalization, ... The Difficulty HTTP is a “stateless” protocol Even persistent connections only last seconds The Trick?

General Idea client server request response + session id (sid) request + sid request + sid request + sid request + sid

Three Ways to Implement Session Tracking URL Re-writing E.g. http://csns.calstatela.edu/index.html;jsessionid=748D9512C9B19B0DCC9477696A88CF12 Hidden form fields Cookies

Cookies Set by the server as a response header Set-Cookie Added to each subsequent request by the browser as a request header Cookie

HTTP Response Example HTTP/1.1 200 OK Date: Mon, 11 Apr 2011 16:53:26 GMT Set-Cookie: JSESSIONID=7E3019D5D76D41E0B42FC1410B0A; Path=/ Content-Type: text/html;charset=ISO-8859-1 Content-Language: en-US Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 2208 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>CSNS</title></head> … …

HTTP Request Example GET /img/style/title_bg.gif HTTP/1.1 Host: csns.calstatela.edu User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:2.0) Firefox/4.0 Accept: image/png,image/*;q=0.8,*/*;q=0.5 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: 115 Connection: keep-alive Cookie: JSESSIONID=7E3019D5D76D41E0B42FC1410B0A

Cookie Attributes Name, Value Host/Domain, Path Controls whether the cookie should be included in a request Require secure connection Max age Comment

Servlet Cookie API Cookie HttpServletResponse HttpServletRequest http://download.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html HttpServletResponse addCookie( Cookie ) HttpServletRequest Cookie[] getCookies()

Example: GuestBook with Cookie Use a cookie to store name so a user only needs to enter their name once

Cookie or No Cookie? Is cookie a potential security problem? Virus? DoS? How about privacy? Cookie manager in Firefox Internet Options in IE

Problems with Cookies Cookies have size limit Malicious users can fake cookie data Sometimes cookie is disabled in browser Cookie API is somewhat tedious to use

Servlet Session Tracking API HttpServletRequest HttpSession getSession() HttpSession http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpSession.html setAttribute( String, Object ) getAttribute( String ) invalidate()

About Session Tracking API Data is stored on the server, i.e. no size limit Each session is assigned a unique session id, which is used to access data associated with the session Session id is randomly generated and hard to fake Session tracking use cookie by default, but can automatically switch to URL rewriting if cookie is disabled

Example: GuestBook Using Session Tracking API Session is shared among servlets Servlet context attributes (a.k.a. application scope variables) vs. session attributes (a.k.a. session scope variables) Similarities?? Differences?? Usage??

Session Configuration in web.xml Default session timeout in Tomcat is 30 minutes Session timeout can be changed in web.xml The timeout value must be an integer Session never timeout if value <= 0 <session-config> <session-timeout>60</session-timeout> </session-config>