Home Answers Viewqa JSP-Servlet Dynamic include of multiple files

 
 


Mark Wilson
Dynamic include of multiple files
1 Answer(s)      8 months ago
Posted in : JSP-Servlet

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 Pages:
Dynamic include of multiple files
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... the following: for (i=0; i < fileArray.length; i++) { include "./" + fileArray
Dynamic include jsp
Dynamic include jsp  I need dynamic include jsp page with an example
jsp:include page=.. and include file = ...
from one jsp file required to include in multiple jsp files...jsp:include page=.. and include file = ...   What is the difference between <jsp:include page = ... > and <%@ include file = ... >
The "include" directive of JSP
to multiple pages. ? The syntax of the include directive is :  ... will discuss about "include" directive of JSP with an example. The include directive : ? Specifies the names of the files to be inserted during
jsp include action tag
jsp 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
php Include
php Include:       Include command provides the opportunity to include several php pages within a single page. This feature facilitates us to save our time. Include takes a file name
The Include Directive in JSP Page
to include the specified file either static or dynamic resource in a JSP page... execution of the include dynamic file on the server, sends back to the calling... The Include Directive in JSP Page   
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Renaming multiple files
Renaming 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
Upload and Download multiple files
Upload 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
Include static files within a JSP page
Include 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.....? - Struts
can 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
Merging multiple PDF files - Framework
Merging 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
Dynamic Proxies - Short Tutorial
Dynamic Proxies - Short Tutorial 2001-01-18 The Java Specialists' Newsletter [Issue 005] - Dynamic Proxies - Short Tutorial Author: Dr. Christoph G... from me, here is a "Short Tutorial to the Java2 platform Dynamic Proxy
save output in multiple text files
save 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
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I........ Need to include jsp file in the same content. The below code doesn't help me " jsp:include page="pageValue" " Please help. Thanks In Adv.  
Create Dynamic Table using Hubernate
to use hibernate. Problem 3: How to upload multiple files to the servlet. I have...Create Dynamic Table using Hubernate  Thank's for reading my Post. I...,password,etc. 2.Media - Allow user to store Mp3 Files.[I have File Id[int],Mp3[LONG
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-select dynamic files. - Java Beginners
java-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
Java read multiple files
Java 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
Uploading the multiple files
. For uploading the multiple files at a time, first create a table as per required...; <HTML> <HEAD> <TITLE> Multiple Files Upload </TITLE>...="#FFFFFF"> <tr> <td><strong>Multiple Files
JSP include directive tag
to a dynamic file. or The JSP include directive is used to include... include directive includes a static file or sends a request to a dynamic file...JSP include directive tag  What is include directive tag in JSP
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
Download dynamic link files to local directory - java code
Download dynamic link files to local directory - java code  Hi, I found a code that downloads static links but not dynamic link files.can anyone give a solution for downloading dynamic link files? Thanks in advance
JSP include
JSP include       A JSP page can include page fragments from other files to form the complete response. There are two include mechanisms: the include directive and the include
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... these two files and store in oracle database as: VendorID,Name,Address and plz
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   
Source file upload by attaching multiple files
Source 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
Include Tag:
Include Tag:       bean:include Tag - is used to load the response from a dynamic application request and make... will learn to use the Struts Html  bean:include tags.  We will cover
Uploading multiple files in JSP - JSP-Servlet
Uploading 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 format
How 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
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
Jsp include page problem
Jsp include page problem  I have included footer.jsp in all my pages. It is working in all pages except search.jsp. In search.jsp (Old footer.jsp... the cache files in your server's work folder. If you are using tomcat, then you
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com... File(inpath); File files[]; files = Folder.listFiles
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source selected from listbox and multiple targets selected from checkboxes. After submitting "next" button it should give me multiple lines drw from one source to respective
JSPs : include Directives
of the file which you want to include. you can include files which are not in WEB...JSPs : include Directives In this section we are going to discuss the include directives which is one part of Directives. include Directives
Dynamic link in JSP
Dynamic link in JSP  Hii everyone...I have stuck from last 2 days... selecting only one "Source" using listbox. And multiple "Targets" using... selecting One source and multiple Targets, i have to generate one table using
creating dynamic buttons in iphone
creating dynamic buttons in iphone  i Have a UIView and i wanted to create a multiple buttons to that should come on view load. It will be great if that can be removed after sometime or required time.   -(void
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 File
have used include directive which includes static files within a jsp page... JSP Include File          JSP Include File is used to insert a html
Dynamic HREF link - Date Calendar
Dynamic HREF link  Hi, I want to know how to create a page with links to download the files present in one folder and if the no of files present... - suppose there are 5 files in the folder then there are 5 links to download
Struts 2 configuration files
Struts 2 configuration files       For developing "Hello World" application you need the following files... either include it in the jar and place in the lib directory of the application
dynamic pagination in jsp - JSP-Servlet
dynamic pagination in jsp  i am unable to display the data in multiple pages. I am gettting data from the database from the javaBeans to jsp by vectors... but i am unable to displaying them in jsp 15 records per page
Action Script 'include' statement example
include statement:-    include '  '; Action script files... Action Script 'include' statement example  ... script files: GeometricalFigures.as and Sqrt.as, and the third example, i.e.
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit the form.Send em the answers as soon as possible..   Please visit

Ask Questions?

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.