----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files. Don't make us guess your problem!!!
----------------------------------------------------------------
Hi,
> I need my JSP page to process another JSP page recursively. The
> process would go like this:
>
> based on the page state, the main page would decide to transfer
> temporary output control to another distinct page, and if that page
> has changed since the last attempt, the JSP-syntax sub-page would
> be recompiled into a Java class, reloaded, and executed, otherwise
> the resident class would just be executed. When that class is done
> its work, flow returns to the parent JSP page.
>
If I understand you right, you want to be able to compute a page's URL, for
example looking it up in a table, *not* by an explicit if-then-else in your
code. You want to be able to get its output and insert the output into the
HTML produced by another page.
If you were using a servlet engine that implements the 2.1 version of the
Servlet specification, such as Tomcat or Jetty (http://www.mortbay.com/),
you might hope to use the RequestDispatcher class and its "include" method,
which is designed as far as I can see to help you solve this kind of
problem.
Unfortunately as a JSP user, while there are many benefits of using JSP,
there seems to be a drawback for you here, related to setting of headers and
the "ContentType" in particular. Every JSP page defines a ContentType, and
JSP implementations set the Content-Type accordingly.
Even in the 2.0 specification, ServletResponse.setContentType is only
supposed to be called once. Now my guess is that most servlet engines don't
enforce this rule; they just let the last setting prevail. But even in this
case you might get an exception if the headers get *sent* and then your
page, or a page it includes, tries to set the ContentType. (For example,
some code may flush the servlet output, which will transmit the headers.)
Depending on the servlet engine you use, and your JSP buffer size, you *may*
be able to get away with this.
You may alternatively be able to use your Web server as a Web client to get
the text you need. For example, make a URL and call methods such as
URL.getContent() to get the contents of your included page, or call
lower-level methods for more control. Performance may be an issue in this
case, since the default handlers open sockets, but perhaps you can cache the
output and reuse it.
We need this sort of ability for our web site because we do a lot of
"co-branding", where we have versions of the site that put our content in
other people's "look and feel" with their logo, or more complex banners and
so on. So we need an extensible scheme for including pages without knowing
their names when we compile the page the does the including.
The older GSP template processor has a method that does just this, but I
guess JSP does not. So we too are looking for a solution that works well
with JSP and with our application.
--
Cris Perdue
Impact Online, Inc.
http://www.volunteermatch.org
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]