Maestro Vladimir
Maestro Vladimir

Reputation: 1196

Dynamic include JSP

i have learned jsp native, i want to include dynamic file. i want to call dynamic page using include

this code

<% String p = request.getParameter("p"); %>

            <%@ include file="pages/"+p+".jsp" %>

if i type dashboard.jsp?p=about the page open "pages/about.jsp"

if i type dashboard.jsp?p=product the page open "pages/product .jsp"

in php this script like this

$p= $_GET['p'];
include(pages/'.$p.'.php');

Upvotes: 2

Views: 7356

Answers (2)

MaDHaN MinHo
MaDHaN MinHo

Reputation: 529

You can Try this code

<%String p="pages/"+request.getParameter("p")+".jsp" %>
<jsp:include page="<%=p %>">
</jsp:include>

instead of this code

<%@ include file="pages/"+p+".jsp" %>

Upvotes: 1

Roman Gordiienko
Roman Gordiienko

Reputation: 76

Similar question Include file from dynamic property value

In your case

<% String p = request.getParameter("p"); 
   String pagePath = "pages/" + p + ".jsp";
%>

<jsp:include page="<%= pagePath %>" ></jsp:include>

Upvotes: 6

Related Questions