[ Team LiB ] Previous Section Next Section

Workshop

The Workshop is designed to help you review what you have learned, and help you to further increase your understanding of the material covered in this hour.

Quiz

1:

What methods of the JSP implicit object session are used to store, retrieve, and delete objects in a session?

2:

What do you have to do so that you can use sessions in a JSP?

3:

What causes a session to expire?

4:

When a session expires, how can I release resources that are associated with it?


Answers

A1:

setAttribute, getAttribute, and removeAttribute are the methods used. Methods of the same name are used with the application object to store attributes that have application scope.

A2:

A JSP that participates in sessions must use a Page Directive Attribute session whose value is true.

A3:

Sessions expire because they are invalidated by a container or by an application. Sessions are often invalidated by a container after a specific amount of time or when the container discovers that a user has done something to invalidate a session, such as close their browser.

A4:

Objects that need to know when a session they are attached to expires can implement the HttpSessionListener interface and make the appropriate changes to the application deployment descriptor.


Activities

  1. Write a JSP that asks a user for their name and a favorite activity. Store the information in an object that is attached to a session. Create another JSP that allows the user to review and change the stored information.

  2. Modify the application you wrote above to provide the option to "publish" their information to the application scope. Add another JSP that shows all of the information for every user who has published their data.

    [ Team LiB ] Previous Section Next Section