views:

220

answers:

2

In a JSP page, there is such code:

<jsp:useBean id="checklog"  class="com.google.admin.guard.CheckLogBean" scope="session" />

and then

<% checklog.checkit(); %>

Why we don't just create the object with new com.google.admin.guard.CheckLogBean? What's the benefit of doing this?

And in the source code, there is no such class, but when we deploy it to server, it works. It seems that the server can pass the class to it?

Thanks.

A: 

The Jsp bean class must be placed under classes folder in WEB-INF. jsp:useBean is an action to instantiate a bean declaratively and with different scopes (session,request, application, and page). Another feature of Bean is The magic of introspection - Java manages this little miracle though a process called introspection that allows a class to expose its methods and capabilities on request.

JavaBeans Components in JSP Pages

SUMMARY: JavaBeans components are Java classes that can be easily reused and composed together into applications. Any Java class that follows certain design conventions can be a JavaBeans component.

adatapost
A: 

The useBean construct is more concise. It allows for lesser usage of script expressions (who doesn't hate them?).

Not so obvious is the fact that the useBean constructs plays well with a designer's toolkit (read Dreamweaver et al), since it relies on a tag, whereas script expressions (to initialize an instance of a bean) do not.

Vineet Reynolds