SoftLiban KEYROUZ Charbel wrote:

>  It is not the style that bothers me rather what is really the
> difference between using import and useBean, for example useBean will
> instantiate the object, plus you have the ability to give it a scope
> and we shouldn't forget the get and setProperty.The problem is, which
> is better import or useBean:If I have an object that will be used for
> one page only?If I have an object that I need unique instances from it
> in several pages?If I have an object that should survive from page to
> page? (this is where I commonly use useBean with session scope)I don't
> need yes and no answers but rather why or the pros and cons. Thank
> you, this is one of the best mailing lists.

The "import" and "useBean" facilities are different.  You use both where
you need them.

The "import" attribute of the <%@ page %> directive is used to generate
"import" statements in the Java source code generated for your JSP
page.  You would use it, for example, if you referenced a particular
class more than once and did not want to fully qualify it all the time
(for exactly the same reasons you would use import in a Java program):

    <%@ page ..... import="java.lang.Vector" %>

    <%
        // Without import, I have to say "java.util.Vector"
        Vector myVector = new Vector;
    %>

No Java objects are created by the import attribute.

<jsp:useBean> is used to actually create a bean (according to the class
you specify) in some appropriate request scope.  See the JSP tutorials
(at JavaSoft's web site and elsewhere) for more information.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to