[ Team LiB ] Previous Section Next Section



Why is a new object created whenever I call jsp:useBean?


You probably forgot to specify a scope for the bean. Remember, the default scope for a bean is page, and all beans with page scope disappear when the page finishes executing.


I changed some bean properties in one page; why don't they show up on my other page?


You might have a scope problem on one of the pages. For example, if you set the properties on a bean with session scope and then you try to access the bean on another page, but you give the bean request scope on the other page, you have two different beans. The second page looks for the bean in its request object and, not finding one there, creates a new instance of the bean, ignoring the one in the session.


I checked to see that the scope is correct; why do I still not see the changes?


You should probably check the bean IDs, too. Make sure they are absolutely identical, character for character. A bean ID of Fred is different from a bean ID of fred.


Why don't some of my parameters get copied into properties?


You probably have a spelling difference between the parameter and the bean property name. Remember, unless you have a BeanInfo class that says otherwise, your bean property names are going to start with a lowercase letter (except when the first few letters of the property are capitalized). The property name looks capitalized in methods such as getFirstName and setFirstName, but the property name is still firstName. Make sure your parameter name matches the case of the property name.


I changed my bean class and recompiled it. Why don't my changes show up?


Many JSP engines don't reload associated classes when they change, only the JSP itself. If you are just testing and don't expect the bean to change in production, or at least not regularly, just restart the JSP engine. If you need to change the bean frequently, you might consider using a JSP engine that automatically reloads associated classes or write a custom class loader.


I know my bean class was reloaded; why do I still not see my changes?


Although new instances of the bean will pick up your changes, any existing beans are probably still using the older code. You need to clear the older beans out of whatever scope they belong to. In other words, if you have an old bean in a session, you need to get rid of it.

    [ Team LiB ] Previous Section Next Section