I am currently trying to learn JSP. My question is, at present I used to include the header and footer of the page using:
<%@include file="includes/header.jsp" %>
and
<%@include file="includes/footer.jsp" %>
But now, I have separated the page content also. So, if user clicks on a page, say products, it has to load the JSP file which is situated in: includes/pages/products.jsp
So, the link to the user is like: <a href="index.jsp?p=products">Products</a>
.
So, I have to get the p value and display the page based on it.
Following is what I have done so far.
<%
if(request.getParameter("p")!=null)
{
String p = request.getParameter("p");
%>
<%@include file="includes/page_name.jsp" %>
<%
}
%>
So, how do I place the value of variable "p" in position of "page_name" ?
Or, is there any other method that I could use ?
In PHP, we could use the include()
or include_once()
. I am bit stuck in this JSP. :(