Solved

jsp:include page="dynamic name.html"

Posted on 2002-04-17
9
298 Views
Last Modified: 2013-11-18
I have pieces of html files in a folder and I want them included inside a jsp with a jsp:include directive. Preciselly, I have a number of files named file100.htm, file101.htm... and I receive an id as parameter when someone access my jsp page : id=101. Inside the jsp page I need to send some data to the client before AND after the inclusion statement so I would need something like this:
<jsp:include page="file<%=id%>.htm"/>

Do I have chances to manage somehow this problem ?
Thank you.
0
Comment
Question by:jorj
  • 5
  • 4
9 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6948371
you can use vars in dynamic includes:
<jsp:include page="<%= varname %>" flush="true" />

or

<jsp:include page="file<%=id%>.htm" flush="true" />

Static includes directives are preprocessed before scripting code executes so you cannot use variables
there.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6948378
for example if your file is called include.jsp

the call is:
include.jsp?id=101

your code will look like:

<% String id = request.getParameter("id");
   if ((id != null) and (id.length() > 0)) { %>
    <jsp:include page="file<%=id%>.htm" flush="true" />
<% }
   else { %>
    No ID parameter!!
<% } %>
0
 
LVL 2

Author Comment

by:jorj
ID: 6948595
no, wrong answer. I don't know what JSP engine you use but mine doesn't allow this. In the meantime I found the answer so I have to close this question with no winner.
Sorry about that but believe me I first tested the method you proposed and only after I posted the question here.

Anyway, the answer is:
<%pageContext.include("file" + id + ".html");%>

I found it by looking into the java code resulted after jsp file was proceessed.
0
 
LVL 2

Author Comment

by:jorj
ID: 6948600
re-post last comments:
no, wrong answer. I don't know what JSP engine you use but mine doesn't allow this. In the meantime
I found the answer so I have to close this question with no winner.
Sorry about that but believe me I first tested the method you proposed and only after I posted the question
here.

Anyway, the answer is:
<%pageContext.include("file" + id + ".html");%>

I found it by looking into the java code resulted after jsp file was proceessed.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:jorj
ID: 6948602
re-post last comments:
no, wrong answer. I don't know what JSP engine you use but mine doesn't allow this. In the meantime
I found the answer so I have to close this question with no winner.
Sorry about that but believe me I first tested the method you proposed and only after I posted the question
here.

Anyway, the answer is:
<%pageContext.include("file" + id + ".html");%>

I found it by looking into the java code resulted after jsp file was proceessed.
0
 
LVL 2

Author Comment

by:jorj
ID: 6948603
re-post last comments:
no, wrong answer. I don't know what JSP engine you use but mine doesn't allow this. In the meantime
I found the answer so I have to close this question with no winner.
Sorry about that but believe me I first tested the method you proposed and only after I posted the question
here.

Anyway, the answer is:
<%pageContext.include("file" + id + ".html");%>

I found it by looking into the java code resulted after jsp file was proceessed.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6948613
that is what JSP include in converted into.. by the servlet engine!

I am not wrong.. look at Sun's documentation of JSP 1.1:
http://java.sun.com/products/jsp/tags/11/syntaxref1112.html
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 200 total points
ID: 6948616
Attributes
page="{relativeURL | <%= expression %>}"

The relative URL that locates the file to be included, or an expression that evaluates to a String equivalent to the relative URL.


The relative URL looks like a pathname-it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP file. If it is absolute (beginning with a /), the pathname is resolved by your Web or application server.
0
 
LVL 2

Author Comment

by:jorj
ID: 6948918
ok, I believe you are right. I am going to reward you.
Thank you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now