Summary

 < Free Open Study > 



In this chapter, we've covered one of the most important features of the Java Servlet API. The session handling interfaces of this API allow you to not only track users across requests by establishing sessions, but they also allow you to maintain state for each session. We saw that the default mechanism used by the API to maintain sessions was to use cookies, but we noted that it is capable of using the URL rewriting mechanism instead, in the case where cookie creation was not permitted by the client.

We built a comprehensive example web application that demonstrated the use of the session handling interfaces and classes, and we saw how we could use event listener classes to notify the application when changes to the Session object occur.

We also saw that while session handling features are useful for storing information in memory, there are associated risks with doing so - particularly in production environments. These risks include loss of performance and reliability. Both of these issues can be addressed by carefully considering which attributes we should add to a session, and for how long we need to keep them in the session.

In the next chapter we will investigate the ways in which we can persist data from our servlets.

A

Activation

  • listening for, 35

attributeAdded() method,

  • HttpSessionAttributeListener interface

  • attribute specific events, listening for, 36

  • e-mail logging class, 39

attributeRemoved() method,

  • HttpSessionAttributeListener interface

  • attribute specific events, listening for, 36

  • e-mail logging class, 39

attributeReplaced() method,

  • HttpSessionAttributeListener interface

  • attribute specific events, listening for, 36

C

classes

  • session management, 15

clusters

  • complexities introduced to application, 41

  • session handling within, 41

Cookie class, javax.servlet.http

  • using cookies in servlets, 7

cookies

  • CookieServlet example, 8

  • establishing session mechanism, 16

  • parameters, 7

  • session tracking using, 6

  • using in servlets, 7

D

data

  • minimizing data stored in sessions, 42

database schema

  • implementing session management, 19

deployment descriptor

  • implementing session management, 27

E

EditNoteServlet

  • implementing session management, 23

elements

  • listener-class> element, 35

e-mail logging class, 39

F

fail-over considerations, 43

form fields, hidden

  • session tracking, 12

G

getAttribute() method, HttpSession interface

  • session management, 17

getAttributeNames() method, HttpSession interface

  • session management, 17

getCreationTime() method, HttpSession interface

  • session management, 17

getId() method, HttpSession interface

  • session management, 17

getLastAccessedTime() method, HttpSession interface

  • session management, 17

getMaxInactiveInterval() method, HttpSession interface

  • session management, 17

getName() method, HttpSessionBindingEvent class

  • attribute specific events, listening for, 37

getServletContext() method, HttpSession interface

  • session management, 17

getSession() method, HttpSession interface

  • session management, 16

getSession() method, HttpSessionBindingEvent class

  • attribute specific events, listening for, 37

getSession() method, HttpSessionEvent class

  • session lifecycle events, 34

getSession() method, HttpSessionListener interface

  • session logging class, 38

getValue() method, HttpSessionBindingEvent class

  • attribute specific events, listening for, 37

H

hidden form fields

  • session tracking, 12

HTTP (Hypertext Transfer Protocol)

  • keep-alive, HTTP 1.1, 2

  • stateless nature, 2

HttpServletRequest class, javax.servlet.http

  • using cookies in servlets, 7

HttpServletResponse class, javax.servlet.http

  • using cookies in servlets, 7

HTTPSession interface

  • session management, 16

HttpSession interface, javax.servlet.http

  • getAttribute() method, 17

  • getAttributeNames() method, 17

  • getCreationTime() method, 17

  • getId() method, 17

  • getLastAccessedTime() method, 17

  • getMaxInactiveInterval() method, 17

  • getServletContext() method, 17

  • getSession() method, 16

  • getting an instance, 16

  • invalidate() method, 18

  • isNew() method, 18

  • removeAttribute() method, 18

  • setAttribute() method, 18

  • setMaxInactiveInterval () method, 18

HttpSessionActivationListener class, javax.servlet.http

  • listening for activation/passivation, 36

  • sessionDidActivate() method, 36

HttpSessionActivationListener interface, javax.servlet.http

  • sessionWillPassivate() method, 36

HttpSessionAttributeListener class, javax.servlet.http

  • attribute specific events, listening for, 36

  • attributeAdded() method, 36

  • attributeRemoved() method, 36

  • attributeReplaced() method, 36

HttpSessionAttributeListener interface, javax.servlet.http

  • attributeAdded () method, 39

  • attributeRemoved () method, 39

  • e-mail logging class, 39

  • log() method, 39

HttpSessionBindingEvent class, javax.servlet.http

  • attribute specific events, listening for, 37

  • getName() method, 37

  • getSession() method, 37

  • getValue() method, 37

HttpSessionBindingListener interface, javax.servlet.http

  • attribute specific events, listening for, 37

  • valueBound() method, 37

  • valueUnbound() method, 37

HttpSessionEvent class, javax.servlet.http

  • getSession() method, 34

  • sessionCreated() method, 34

  • sessionDestroyed() method, 34

HttpSessionListener interface, javax.servlet.http

  • implemented, 38

  • session lifecycle events, 34

  • sessionCreated() method, 34

  • sessionDestroyed() method, 34

I

interfaces

  • session management, 15

invalidate() method, HttpSession interface

  • session management, 17

isNew() method, HttpSession interface

  • session management, 17

K

keep-alive, HTTP 1.1, 2

L

listener> element

  • HttpSessionListener interface, 35

listener-class> element

  • HttpSessionListener interface, 35

ListNotesServlet

  • implementing session management, 21

log() method, HttpSessionAttributeListener interface

  • e-mail logging class, 39

M

methods

  • attributeAdded() method,

    • HttpSessionAttributeListener interface, 36, 39

  • attributeRemoved () method,

    • HttpSessionAttributeListener interface, 39

  • attributeRemoved() method,

    • HttpSessionAttributeListener interface, 36

  • attributeReplaced() method,

    • HttpSessionAttributeListener interface, 36

  • getAttribute() method, HttpSession interface, 17

  • getAttributeNames() method, HttpSession interface, 17

  • getCreationTime() method, HttpSession interface, 17

  • getId() method, HttpSession interface, 17

  • getLastAccessedTime() method, HttpSession interface, 17

  • getMaxInactiveInterval() method, HttpSession interface, 17

  • getName() method, HttpSessionBindingEvent class, 37

  • getServletContext() method, HttpSession interface, 17

  • getSession() method, HttpSession interface, 16

  • getSession() method, HttpSessionBinding class, 37

  • getSession() method, HttpSessionEvent class, 34

  • getValue() method, HttpSessionBindingEvent class, 37

  • invalidate() method, HttpSession interface, 18

  • isNew() method, HttpSession interface, 18

  • log() method, HttpSessionAttributeListener interface, 39

  • removeAttribute() method, HttpSession interface, 18

  • sessionDidActivate() method,

    • HttpSessionActivationListener interface, 36

  • sessionWillPassivate() method,

    • HttpSessionActivationListener interface, 36

  • setAttribute() method, HttpSession interface, 18

  • setMaxInactiveInterval() method, HttpSession interface, 18

  • valueBound() method,

    • HttpSessionBindingListener interface, 37

  • valueUnbound() method,

    • HttpSessionBindingListener interface, 37

MySQL

  • download web site, 19

N

NotePad application

  • attribute specific events, listening for, 38

  • compiling and running, 28

  • database schema, 19

  • deployment descriptor, 27

  • implementing session management, 18

  • NotePadServlet implementing session management, 20

  • redeploying, 40

  • URL rewriting, 30

P

passivation

  • listening for, 35

R

references to web sites

  • MySQL download, 19

removeAttribute() method, HttpSession interface session management, 18

replication

  • when to replicate sessions, 42

resource-ref> element

  • session lifetime, 34

S

serialization

  • making session attributes serializable, 42

Servlet 2.3 API

  • session management using, 15

servlet> element

  • HttpSessionListener interface, 35

  • redeploying NotePad application, 40

servlet-mapping> element

  • session lifetime, 34

servlets

  • cookies, using in, 7

session handling, 1

  • making session attributes serializable, 42

  • minimizing data stored in sessions, 42

  • when to replicate sessions, 42

  • within clusters, 41

session inactivity

  • session lifecycle, 34

session lifecycle events

  • diagrammatic representation, 32

  • listening for, 32

  • session creation/termination, listening for, 33

session lifetime

  • session lifecycle, 34

session listener

  • activation, listening for, 35

  • attribute specific events, listening for, 36

  • passivation, listening for, 35

session logging class, 38

session management

  • classes, 15

  • HTTPSession interface, 16

  • implementing, 18

  • interfaces, 15

  • Servlet API, using, 15

session see sessions/session management.

session state

  • maintaining, 3

session tracking

  • cookies, using, 7

  • hidden form fields, using, 12

  • URL rewriting, using, 3

sessionCreated() method, HttpSessionListener interface

  • session lifecycle events, 34

  • session logging class, 38

sessionDestroyed() method, HttpSessionListener interface

  • session lifecycle events, 34

  • session logging class, 38

sessionDidActivate() method,

  • HttpSessionActivationListener class

  • listening for activation/passivation, 36

sessions/session management

  • establishing session mechanisms, 16

sessionWillPassivate() method,

  • HttpSessionActivationListener interface

  • listening for activation/passivation, 36

setAttribute() method, HttpSession interface

  • session management, 18

setMaxInactiveInterval() method, HttpSession interface

  • session management, 18

setMaxInactiveInterval() method, Session object

  • session inactivity, 34

SSL (Secure Sockets Layer)

  • establishing session mechanism, 16

state

  • HTTP, 2

  • why track user identity, 2

state see session state.

U

URL rewriting

  • establishing session mechanism, 16

  • NotePad application without cookies, 30

  • session tracking using, 3

V

valueBound() method, HttpSessionBindingListener interface

  • attribute specific events, listening for, 37

valueUnbound() method,

  • HttpSessionBindingListener interface

  • attribute specific events, listening for, 37

W

welcome pages

  • implementing session management, 20



 < Free Open Study > 



Professional Java Servlets 2.3
Professional Java Servlets 2.3
ISBN: 186100561X
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net