Solved

jsp:include page="dynamic name.html"

Posted on 2002-04-17
9
303 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
struts spring hibernate example 12 131
Create and populate iFrame onClick of a button? 1 86
how to add new optional parameter to JSP 1 49
running on tomcat not jboss eap 7.0 3 17
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

766 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