Jose E Herrera wrote:
> Does anyone know of a way to compile a JSP into a class that can be invoked
> by methods within a single servlet.
> For example:
> let's say I have 5 JSPs (we'll keep the # low for now), I have one
> point of entry to my application, one servlet.
> So, what I want to be able to do is call any of these JSPs, as objects
> from my doget method in my entry point servlet.
>
> Has anyone done somthing similar?
>
Sure ... all the time.
The standard approach to doing this is to use a RequestDispatcher. You can
either have your servlet forward control to the JSP page, which will generate
output based on beans that the servlet has stuffed into the request or the
session, or you can include the output of the JSP page in the page being
created by your servlet. You can do the same trick from a JSP page to another
JSP page (or a servlet) using <jsp:include> and <jsp:forward> -- these actions
utilize request dispatchers under the covers.
Note that you never deal with these things as "objects" (i.e. classes where
you can call the methods). There is in fact no way in the current servlet API
to get an object reference to another servlet. Allowing this would introduce
both security risks and the chance for servlets to corrupt the servlet
lifecycle that the API requires them to support. Instead, the request
dispatcher gives you a nice clean way to what amounts to a server-side
redirect or a server-side include.
Check out the servlet API documentation on RequestDispatcher for the details,
and also the example servlets and JSP pages that are included in the JSWDK.
>
> Thanks,
>
> Jos
>
Craig McClanahan
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
For JSP FAQ, http://www.esperanto.org.nz/jsp/jspfaq.html