Solved

jsp:include page="dynamic name.html"

Posted on 2002-04-17
9
301 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
recommended CMS for the website revamp 3 98
Market Place not working in Eclipse Luna 2 112
equalIsNot  challenge 43 138
login jsp example 24 46
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

808 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