
I want to include a series of small files, based on a string. For instance, if the string was: String fileString="a b c d e"; I would split it into an array, fileArray, and do something like the following:
for (i=0; i < fileArray.length; i++) {
include "./" + fileArray[i] + ".inc.jsp";
}
Since each included file (in this case) is going to be a call to a table-building routine, each will look something like this:
out.write(myTableFunction(SourceName, sourceElement, "fieldname", "cname",
new String [] { "errorField" },
new String [] { "Hdr1", "Hdr2", "Hdr3", "Hdr4" },
new String [] { "fld1", "fld2", "fld3", "fld4" },
new int[] { flag1, flag2, flag3, flag4 }
))
The idea is that the list of tables to be built will change pretty often, and by simply updating the list of filenames, I can change which tables are built, and in which order. I've attempted things like:
for (i=0; i < fileArray.length; i++) {
String fn = "./" + fileArray[i] + ".inc.jsp";
%><jsp: include '<%= fn %>' /><%
}
But that throws various errors, such as undefined variables (sourceElement). Is what I'm basically trying to do even theoretically possible? Does anyone have any examples of something similar working? (Sorry I can't post actual code, but the project is on a closed intranet.)

I think the include HAS to be an include directive, to make the included code work properly, recognize variables, etc:
<%@ include file="myfile.jsp" %>
This works perfectly. However, what I need is to be able to (1) make the file name be a variable value, and then (2) do that in a loop.
So, IF I could do something LIKE the following, I'd be as far as #1:
<% String fn = "myfile.jsp" %> <%@ include file=fn %>
The error message says it's looking for quotes; putting quotes doesn't help, since there's no file "fn".
Any way to do this, or does the file name value HAVE to be a static piece of code?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.