If you put your setter code (<jsp:setProperty>) inside the body of <jsp:useBean>, the property setting is conditional! In other words, the property values will be set only if a new bean is created. If an existing bean with that scope and id are found, the body of the tag will never run, so the property won’t be reset from your JSP code.
With a <jsp:useBean > body, you can have code that runs conditionally... ONLY if the bean attribute can’t be found and a new bean is created.
Q: Why didn’t they just let you specify arguments to the constructor of the bean? Why do you have to go through the extra trouble of setting values anyway?
A: The simple answer is this: beans can’t HAVE constructors with arguments! Well, as a Java class, they can, but when an object is going to be treated as a bean, Bean Law states that ONLY the bean’s public, no-arg constructor will be called. End of story. In fact if you do NOT have a public no-arg constructor in your bean class, this whole thing will fail anyway.
Q: What the heck is Bean Law?
A: The law according to the creakingly-ancient JavaBeans specification. We’re talking JavaBeans—NOT Enterprise JavaBeans (EJB) which is completely unrelated. (Go figure.)The plain old non-enterprise JavaBeans spec defines what it takes for a class to be a JavaBean. Although the spec actually gets pretty complex, the only things you ...