1 / 15

CS320 Web and Internet Programming Cookies and Session Tracking

CS320 Web and Internet Programming Cookies and Session Tracking. Chengyu Sun California State University, Los Angeles. Session Tracking. The Need shopping cart, personalization, ... The Difficulty HTTP is a “stateless” protocol Even persistent connections only last seconds The Trick??.

edric
Download Presentation

CS320 Web and Internet Programming Cookies and Session Tracking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS320 Web and Internet ProgrammingCookies and Session Tracking Chengyu Sun California State University, Los Angeles

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

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

  4. Three Ways to Implement Session Tracking • URL Re-writing • Hidden form field • Cookies

  5. Example: Shopping Cart (I) • Using URL re-writing • Using hidden form field

  6. Cookies • Issued by the server • HTTP Response: Set-Cookie • Part of the next client request • HTTP Request: Cookie

  7. Cookie Attributes • Name, Value • Host/Domain, Path • Require secure connection • Max age • Comment (Version 1)

  8. Servlet Cookie API • Cookie • getThis(), setThat() ... • setMaxAge( int ) • 1000??, -1??, 0?? • HttpServletResponse • addCookie( Cookie ) • HttpServletRequest • Cookie[] getCookies()

  9. Example: Shopping Cart (II) • Using Cookie

  10. Cookie or No Cookie? • Is cookie a potential security problem? • Virus?? • DoS?? • How about privacy? • Cookie manager in Mozilla/Firefox(?) • Internet Options in IE

  11. It’s Not Easy ... • ... to generate unique and random session id’s • ... to associate more information with a session • ... to tell whether the client has already left

  12. Servlet Session Tracking API • HttpServletRequest • HttpSession getSession() • HttpSession • setAttribute( String, Object ) • getAttribute( String ) • setMaxInactiveInterval( int ) • Tomcat default: 30 seconds • invalidate()

  13. Example: Shopping Cart (III) • Using Session Tracking API

  14. Is Session Shared Across Multiple Servlets? Example: Members Only! Username: Password: LoginServlet DisplayServlet

  15. Is Session Shared Across Multiple Servlets? • LoginServlet • Validate username and password • Failed: redirect to error page • Succeeded: set a session attribute “authenticated” to “true”, and redirect to DisplayServlet • DisplayServlet • Check session attribute “authenticated” • null: redirect to LoginServlet • “true”: display content

More Related