Link to home
Start Free TrialLog in
Avatar of jorj
jorjFlag for Romania

asked on

jsp:include page="dynamic name.html"

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.
Avatar of cheekycj
cheekycj
Flag of United States of America image

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
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!!
<% } %>
Avatar of jorj

ASKER

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.
Avatar of jorj

ASKER

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.
Avatar of jorj

ASKER

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.
Avatar of jorj

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of cheekycj
cheekycj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jorj

ASKER

ok, I believe you are right. I am going to reward you.
Thank you.