Rajesh Nagarjunan wrote:

> Hi
>
>     I have been trying to locate some information on how I can use the
> reusable classes (not beans but close to beans) that was developed for
> other project in my new project with Jsp architecture.... I found that
> none of the online tutorials nor FAQ's discussed about this point.
>
>     I initially thought that this was not possible in JSP as most of the
> issues discussed were related to Beans and <Bean> tag's etc...
>
>     It took me some time but figured out that if I just wanna use some
> service of a reusable set of class rather than some advanced features
> like automatic session storage of beans... then it would be best for me
> to instantiate an object of my reusable class and use the services
> rather than going in for a bean...
>
>     <%
>             DBInterface dbObject = new DBIterface();
>             dbObject.executeQuery();
>               . . . . . .
>              . . . . .
>     %>
>

The minimal requirement for making your reusable classes useful in JSP pages is
that they have a public no-arguments constructor.  If that is the case for you
(which appears to be so if your above scriptlet is accurate), you can:

    <jsp:useBean id="dbObject" class="DBInterface" scope="page"/>

and get the same result as the first line of your scriptlet.  Alternatively, if you
need to make the object visible to the request or the session, just change the
scope attribute and the JSP page compiler will also store the object away for you
as well.

>
>     I just thought that adding this as a part of the tutorial or the FAQ
> will surely be very useful for most of the beginners...
>
>     Please feel free to pass your comments on this and correct me if I
> am wrong.
>

There are different viewpoints on whether embedding Java scriptlets in your JSP
page is good programming style or not.  Personally, I am of the opinion that this
approach is *not* a good idea at all, because you are mixing presentation logic and
business logic together -- making it very hard to modify one aspect of your
application (say, the look and feel of the pages) without messing up another aspect
as well (how the data is accessed).  If I find myself having to include a scriptlet
(instead of, say, building an appropriate custom tag), then I consider it a bug in
my design.

That's my opinion ... others will disagree.

>
>     Thanks
>
>     Cheers
>     Rajesh Nagarjunan
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to