Question

Just hoping to clarify:

In a JSP page, would it be correct to say that <jsp:useBean> performs the same function as the new keyword used within a scriptlet?

I understand some of the benefits of standard actions, just making sure I'm solid on the fundamentals.

(Saw a similar question here: use of <jsp:useBean> tag, but couldn't find a clear answer).

Thanks, Jeff

Was it helpful?

Solution

Not quite, useBean first looks for a bean with the given ID, but if it is not present in the scope defined, it will then be created.

From Oracle's documentation:

The jsp:useBean element declares that the page will use a bean that is stored within and accessible from the specified scope, which can be application, session, request, or page. If no such bean exists, the statement creates the bean and stores it as an attribute of the scope object (see Using Scope Objects).

So you won't be guaranteed a new object if one already exists in your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top