Pekowsky Larne wrote:

> > I try to include different pages with the same prefixe and suffixe but with
> > a variable between:
> >
> > for (int i=1; i<10; i++)
> >     <%@include file= "something" + i + ".html" %>
>
> There's no way to do this at translation time, but you could get the
> same effect if you're willing to do it at request time and use a
> scriptlet instead of a JSP tag:
>
> <%
> ServletConfig sconf  = getServletConfig();
> ServletContext scont = sconf.getServletContext();
>
> for(int i=0;i<10;i++) {
>    RequestDispatcher rd = scont.getRequestDispatcher(
>                                 "/something" + i + ".html");
>    rd.include(request,response);
> }
>
> %>
>
> Note the paths you pass to getRequestDispatcher() must start with a
> slash.
>
>                                                   - Larne Pekowsky
>

You can do the same thing with <jsp:include> if your JSP engine correctly
implenents the spec with regard to request time attributes:

<% for (int i = 0; i < 10; i++) {   %>
    <jsp:include page="<%= "/something" + i + ".html" %>" flush="true" />
<% } %>

If you look at the Java code generated for this, it will probably look very much
like what Larne proposed above, since JSP pages are actually turned into servlets.
 But this is a little easier to write, and once the tag extension facilities of
JSP 1.1 are available (and a looping tag is created), you will be able to do it
without any scriptlets at all.

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