Difference between jsp:useBean and page import package ???

U

Ulf Meinhardt

Ok on a Java Server Page I can use a function in two ways:
Either I declare
<jsp:useBean id="myBean" scope="session" class="mypack.mysubpack.MyClass" />
or I declare
<%@ page import = "mypack.mysubpack.MyClass" %>

In each case I can call a function later by coding

MyClass.myFunction();

So what is the difference between the two variantes?

Why are Beans invented if we don't need them because we have the import statement ?

Ulf
 
T

Tor Iver Wilhelmsen

Ok on a Java Server Page I can use a function in two ways:
Either I declare
<jsp:useBean id="myBean" scope="session" class="mypack.mysubpack.MyClass" />

This checks if an object called "myBean" exists in the session
attributes, and if necessary creates and puts it there. It also adds a
variable called "myBean" that can be referenced later, in e.g.
or I declare
<%@ page import = "mypack.mysubpack.MyClass" %>

This does nothing more than add an import statement in the beginning
of the generated servlet.
In each case I can call a function later by coding

MyClass.myFunction();

So what is the difference between the two variantes?

See above.
Why are Beans invented if we don't need them because we have the
import statement ?

Because beans aren't limited to what you artificially limit them to.
You can do much more with beans than just call static methods in their
classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top