Solved

jsp:include page="dynamic name.html"

Posted on 2002-04-17
9
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

749 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