- Using Hidden Controls
- The Cookie Class
- The HttpServletResponse Interface
- Creating a Cookie
- Reading a Cookie
- Setting and Reading a Cookie in the Same Page
- Using Sessions
- Creating a Session
- Setting Session Timeouts
- Using Applications
- Using Sessions, Applications, and JavaBeans
- Summary
- Q&A
- Workshop
Workshop
This workshop tests whether you understand all the concepts you learned today. It's a good idea to master today's concepts by honing your knowledge here before starting tomorrow's material. You can find the answers to the quiz questions in Appendix A.
Quiz
What are the names of the Cookie object methods you use to find a cookie's name and value?
What is the default timeout for a session in the Tomcat server?
How do you know if Tomcat can't establish a session with the user's browser?
What possible scopes can you use with JavaBeans in JSP?
What is the default setting for the page directive's session attribute?
Exercises
Create a sample home page that accepts a person's name and birthday using text fields (use text fields for the name, birth month, and birth day) and stores that information using a cookie that lasts a year. Then use the Date and Calendar classes you saw in Day 6, "Creating JSP Components: JavaBeans," to display a greeting to the person on his birthday.
Try repeating the JavaBean example in the topic "Using Sessions, Applications, and JavaBeans," but this time, give the bean application scope to create a Web page counter that uses the counter in the bean to indicate the total number of times the page has been accessed by anyone, and then test it out. Also, use the application object's setMaxInactiveInterval method to set the application timeout to a second or two and watch what happens to the counter as the application times run out over repeated page reloads.