What happens when a session times out in a JSP page and I then try to access a session-scoped bean?

Ryan Breidenbach

This depends on how you try to access the bean. If you try to access it through the <jsp:useBean ... /> tag and the session has timed out (or if it is new user that has no session), the JSP will create a new bean. This is possible because only classes that conform to JavaBean rules can be used in the <jsp:useBean .../> tag. Since all JavaBeans must have a default constuctor, the JSP simply creates a new object of the bean's class by calling its default constuctor. Therefore, the bean the JSP will be using will have your bean's default values.

However, if you attempt to access an object stored in a session that does not exist (because the session is new, timed out, etc) through the getAttribute(), null will be returned.