Dynamic include of multiple files
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.)
View Answers
September 4, 2012 at 8:52 PM
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?
Related Tutorials/Questions & Answers:
Dynamic include of multiple filesDynamic include of
multiple files I want to
include a series of small
files, based on a string.
For instance, if the string was:
String fileString... the following:
for (i=0; i < fileArray.length; i++) {
include "./" + fileArray
Advertisements
Reading multiple xml filesReading
multiple xml files How can we read many xml
files from a folder? The same procedure as that of "listfiles
Upload and Download multiple filesUpload and Download
multiple files Hello Sir/Madam,
I need a simple code for upload and download
multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
Renaming multiple filesRenaming
multiple files Hi,
I have number of
files in a directory.
Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. ....
Now I wanted to rename these
files as: 1RohitBBorse.mp4
Merging multiple PDF files - FrameworkMerging
multiple PDF files I m using the iText package to merge pdf
files. Its working fine but on each corner of the merged filep there is some... the
files are having different font.Please help
save output in multiple text filessave output in
multiple text files Hi..I'm getting problem to store the output of this php code into
multiple text
files. Can anyone sugeest.
Here is my code:
<?php
for($i=1; $i<=100; $i++)
{
$html = file_get
Uploading Multiple Files Using Jsp Uploading
Multiple Files Using Jsp
... to understand how you can upload
multiple files by using the Jsp.
We should avoid... a file.
In
this example we are going to tell you how we can upload
multiple files Java read multiple filesJava read
multiple files
In this section you will learn how to read the data of
multiple files. Here we have created four
files that includes information.... We have to find the students according to particular school from all the
files Include static files within a JSP pageInclude static
files within a JSP page How do I
include static
files... using the JSP
include directive. This way, the inclusion is performed just once... for the file attribute. Although you can also
include static resources using
can we use include files in struts.....? - Strutscan we use
include files in struts.....? hi,
i have a doubt that whether we should not redirect from one jsp to another jsp directly using
include r jsp:
include directives. I heard that it is violation of struts rules if we
Uploading the multiple files. For uploading the
multiple files at a time, first create a table as per required...;
<HEAD>
<TITLE>
Multiple Files Upload </TITLE>
<BODY>...;#FFFFFF">
<tr>
<td><strong>
Multiple Files Upload </strong>
Copy multiple files
Copy
multiple files
In this section, you will learn how the data of
multiple files.... For copping the data of
multiple file, you need all
files in a specified directory where
Source file upload by attaching multiple filesSource file upload by attaching
multiple files Hi,
I am trying to develop a file upload with
multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Source file upload by attaching multiple files a provision to attach
multiple images/
files like in gmail. Is there any solution...Source file upload by attaching
multiple files Thanks for the answer. The answer posted in this link
I want to have a single text box and when i
java-select dynamic files. - Java Beginnersjava-select
dynamic files. My java program is processed
files. Now i have set inputfile is default location. i want to change input file location in run time. How to insert new
files in run time.
I need to take system file
Uploading multiple files in JSP - JSP-ServletUploading
multiple files in JSP Hi,
I have this code in JSP for Uploading
multiple files :
Samples : Simple Upload... modification I need to do in the code to upload all the
files attached.
How to convert multiple files in java to .zip formatHow to convert
multiple files in java to .zip format i receive
multiple files from a remote URL as
for (String reportid : reportList...://Answers//Examples");
File[]
files = folder.listFiles();
File file=new File
Uploading Multiple Files Using Jsp Uploading
Multiple Files Using Jsp
... to understand how you can upload
multiple files by using the Jsp.
We should avoid... a file.
In
this example we are going to tell you how we can upload
multiple files JSP Include jsp include either a
static or
dynamic file in a JSP file. If the file is static, its text or content
is included in the calling JSP page. If the file is
dynamic...
JSP
Include jsp
jsp:include action tag jsp:
include action tag
In this section we will discuss about JSP "include" action tag. The jsp "include"
tag is used to
include the resource at the request time. It is better for
dynamic web page. The
include tag
JSP Include Param
JSP
Include Param
JSP
Include Param is used to pass parameter in the
include directive. The
example uses <jsp:param> clause to pass
Include Tag:Include Tag:
bean:
include Tag - is used to load the response from a
dynamic application request and make...:include>
tag.
Here you will learn to use the Struts Html bean:
include files/core/
files/storeobjectsinFile.html
filesfiles write a java program to calculate the time taken to read a given number of
files. file names should be given at command line.
Hello Friend,
Try the following code:ADS_TO_REPLACE_1
import java.io.*;
import
JSP include
JSP
include
A JSP page can
include page
fragments from other
files to form the complete...
include
action
The
include action allows you to
insert
files into the page
jsp:include page=.. and include file = ... from one jsp file required to
include in
multiple jsp files.ADS_TO_REPLACE_1...jsp:
include page=.. and
include file = ... What is the difference between <jsp:
include page = ... > and
<%@
include file = ... >
jsp include action tagjsp
include action tag Defined jsp
include action tag ?
The <jsp:include> element allows you to
include either a static or
dynamic file in a JSP file. The results of including static and
dynamic files are quite
require() and include() require() and
include() hii,
What is the difference between require() and
include() in php?
hello,ADS_TO_REPLACE_1
The require... Error.
The
include() statement includes and evaluates the specified file.
include include taginclude tag good morning sir. This is venu sir.i am pursing mca .
I am learning struts2 but i have a small doubt i am using
include tag.
ex...
include tag ..... is not displayed
Thanks
venuADS_TO_REPLACE_1
include taginclude tag Good morning sir. This is venu sir.i am pursuing mca .
I am learning struts2 but i have a small doubt i am using
include tag.
ex
welcome to rose India.net
include value="myBirthday.jsp" ADS_TO_REPLACE_1
How to include?How to
include? How can we
include a JSP file in one application to the JSP file in another application which are in the same server?? please help me out with code
php includephp include i'm trying to
include a header on my page but it doesn't display anything
here's my code
JSP include directive tag to a
dynamic file.ADS_TO_REPLACE_1
or
The JSP
include directive is used... or sends a request to a
dynamic file.
orADS_TO_REPLACE_3
The JSP
include directive...JSP
include directive tag What is
include directive tag in JSP
dynamic reportdynamic report i need complete code for generating
dynamic report in jsp