This brings up a question I've been trying to figure out... why does the
"jsp:useBean" exist at all?  (Versus just doing a "new myClass()"?)

Are there technical reasons for it?  The only thing I could think of was
that forcing the JSP writer to do the "new" was too "Java", and giving
then the "jsp:useBean" was more "HTML", thus aiding the role separation
of programmer and HTML (JSP) developer.

Thoughts?

Thanks,
Scott


Jim Preston wrote:
>
> Well, I'm curious as to why you think using an include to do what you want
> is kludgy and error prone. I guess I could maybe understand why you'd think
> it was a little kludgy if the code in question doesn't have anything to do
> with what's on the JSP, but what's error prone about it?
>
> In any case, why don't you just put your code in a method in a bean and then
> call that method from the JSP? There's nothing that restricts beans to being
> used only for property setting/getting; they're just classes, they can have
> any arbitrary methods, and you can call those methods from your JSP just
> like you can from "ordinary" Java. For example, at the top of your JSP, put
> this:
>
> <jsp:useBean id="behindTheScenes" class="BehindTheScenes"/>
> <% behindTheScenes.doEntryStuff();%>
>
> Or you don't even have to make it a bean, you could just do this (which is
> actually slightly more efficient, since it doesn't have to go through the
> bean instantiator):
>
> <%BehindTheScenes behindTheScenes = new BehindTheScenes();
>   behindTheScenes.doEntryStuff();
> %>
>
> And in either case you can do this at the bottom:
>
> <% behindTheScenes.doEndStuff();%>
>
> Never forget what the "J" stands for; you can put real Java in a JSP. It all
> gets compiled into a method in a servlet where the HTML is just a bunch of
> out.println's. Look at it that way, and some difficult questions become a
> lot easier.
>
> --Jim Preston
>
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Williams, Stephen
> Sent: Thursday, July 06, 2000 10:07 AM
> To: [EMAIL PROTECTED]
> Subject: Extending JSP pages
>
> I'd like to have all of my JSP pages execute a certain chunk of Java code
> before the page is displayed, and then execute another chunk of Java code
> after the page is displayed.  I could use an "include" at the top and bottom
> of each of my JSP pages, but this seems a little kludgy and error-prone.
> Another way to do this might be to have all my JSPs extend a subclass of
> HttpJspPage that I create.  However, I'm wary of doing this because Sun's
> JSP documentation states that extending the JSP page "limits the JSP
> container's ability to provide a specialized superclass that improves the
> quality of the compiled file."
>
> Does anyone have any experience with extending JSP pages through the use of
> the "page extends" directive?  If so, what advice do you have for someone
> thinking about doing it (e.g., gotchas, benefits)?
>
> Alternatively, has anyone created a workaround for extending the JSP page
> that accomplishes the same thing.
>
> Thanks.
>
> --
> Stephen A. Williams
> HNC Telecommunications Solutions
>
> ===========================================================================
> 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
>
> ===========================================================================
> 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

===========================================================================
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