Ch6 conversational state

Post on 04-Jul-2015

716 views 2 download

description

Cookies and such

Transcript of Ch6 conversational state

Εξέταση 2ης εργασίας

• Παρακαλώ οι παρακάτω να παραμείνουν την 2η ώρα για να συζητήσουμε την εργασία τους

546(alkis), 593 (antonis), 917(thodoros), 935, 941, 959(sotiri), 989, 996(alexandros), 1502(evi), 1557

3η εργασίαΜελετήστε το 5ο κεφάλαιο του βιβλίου Head First Servlets & JSP, Second Edition, και προσπαθήστε τις ερωτήσεις της εξέτασης.

Χρησιμοποιήστε τον σύνδεσμο http://www.datadisk.co.uk/html_docs/jsp/jsp_mvc_tutorial.htm για να υλοποιήσετε μια web application η οποία θα μας βοηθάει να επιλέξουμε το είδος του καφέ που επιθυμούμε.

Καταθέστε την εργασία σας πριν τις 08.00 της Δευτέρας 27 Οκτωβρίου συμπληρώνοντας την παρακάτω φόρμα.

Εργασία εξαμήνου

Δώστε τις προτάσεις σας και συζητήστε τες μαζί μου.

Conversational StateChapter 6

Conversational state• Web servers have no short-term memory. As soon as they close

connection to your session they forget you.

• Most of the time this is what you need

• Sometimes you do need to keep the conversation with the container alive for awhile.

• Keep client specific state across multiple requests

Implement

• Use a stateful session enterprise javabean

• Use a database

• Use an HttpSession

How Sessions

Work

Clients & Sessions

• HTTP is stateless

• HTTPS is not but it is heavy in many respects

• Unique IP is not enough

Unique Session ID

Cookies

Let the container do most

Get or set

HttpSession session = request.getsession();

Existing or not?

Pre-existing session?

URL re-writing

URL re-writing only after encoding

Summary for get.Session()I want a session for THIS client

A session that matches the session ID sent or

A new session

The session is with the client associated with the request

You need to do some killing

• Authority  to  kill  – Container  – You  

• Ways  to  kill  – timeout  – invalidate()  – crash

Killing Sessions

All  sessions

Only  the  session  you  call  

from

Death by timeout

• Cookies  are  sweet  because  the  container  takes  care  of  during  a  session.  

• You  may  keep  a  cookie  across  sessions  too.

Using Cookies

No  getCookie(String)

Using Cookies with Servlet API

Example  (SET  &  send)

Example  (GET)

Cookies  are  not  Headers!

Milestones

Session  is  not  duplicated

Session on different VMs

Session  Migration

Session  related  Listeners

Listeners  &  API