Hi All, i have a curiousity regarding "jsp:useBean" tag. When we have to import classes for using "jsp:useBean" tag then why don't we make the objects straight away using that class constructor. Is that something to do with scope?Also are these objects created at compile time itself ? Kindly explain to me in detail. Thanks in advance
I'm not sure what you asking in your first question. But, since the bean can be in any scope, it can't be set/created at compile time. In fact, the JSP may not even need to ever create the bean being used. It may have been constructed and stored in a context by some Servlet during initialization much earlier.
Hi Nathaneil, Actually i wanted to know the difference between object of a bean created by normal method i.e.(using new()) and by using jsp:useBean tag.if no difference is there then why do we at all use jsp:useBean tag?
jsp:useBean does more than create an instance of the class. If it finds a bean with the specified name already in the specified scope, it doesn't create a new instance at all -- it just hooks up the existing bean to the scrpting variable. When an instance is created, it is placed in the specified scope. This isn't anything you could not do with a scriptlet on the page, but is handier and helps keep Java scriptlets out of the page.