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');

2 Answers

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest