Kyle, make sure you read up on your "JSP includes" -- the one that Joel is
giving your works DIFFERENTLY than the include you were using before.
Specifically, in your original example, it didn't work because the <@
include happens during COMPILATION -- not during RUNTIME.  Your problem was
that you were trying to branch at runtime and that was just too late for a
"<@ include".

The include shown in Joel's code happens at runtime, that is why it works.
However, it won't have any local variables available to it unless the are
put into the request or into the session and retrieved on the next page
(index.jsp, anotherPage.jsp, or yetAnother.jsp in Joel's example)

There's quite a bit written about different JSP includes ... do some
studying!

-----Original Message-----
From: Joel Kozlow [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 23, 2001 12:12 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Include question...


Sure it is...just do this...

<%
        String sPage = "index.jsp";

        if (myCondition()) {
                sPage = "anotherPage.jsp";
        }
        else if (anotherCondition()) {
                sPage = "yetAnother.jsp";
        }
%>
<jsp:include page="<%= sPage %>" flush="true" />


Hope that helps.

- Joel Kozlow


-----Original Message-----
From: Kyle Burke [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 23, 2001 10:40 AM
To: Tomcat-Users
Subject: Include question...


Is this possible (see <CODE>)?  I have a file that depends on the query
string for display.  Can I have include files based on that query string
too?

If action=edit show the data in form fields otherwise show it in formatted
text.

When the files are included vs. when the page is compiled and executed (see
<EXCEPTION>).  Thanks peops!


<EXCEPTION>
Unable to compile class
'try' without 'catch' or 'finally'
but I dont have any exception handling in the page.
</EXCEPTION>

<CODE>
<%
    if(action.equals("edit")){
%>
<%@ include file="includes/edit_staff.jsp"%>
<%
   }else{
%>
 <%@ include file="includes/view_staff.jsp"%>
<%
}
%>
</CODE>


Kyle Burke

Reply via email to