JSP include action tag by R4R Team

JSP include action tag:

Include action tag is used for including another resource to the current JSP page. The included resource can be a static page in HTML, JSP page or Servlet. We can also pass parameters and their values to the resource which we are including. Below I have shared two examples of <jsp:include>, one which includes a page without passing any parameters and in second example we are passing few parameters to the page which is being included.

Syntax:

1) Include along with parameters.

<jsp:include page="Relative_URL_Of_Page">

<jsp:param ... />

<jsp:param ... />

<jsp:param ... />

...

<jsp:param ... />

</jsp:include>


2) Include of another resource without sharing parameters:


<jsp:include page="Relative_URL_of_Page" />

Relative_URL_of_Page would be the page name if the page resides in the same directory where the current JSP resides.

Example 1: <jsp:include> without parameters:

In this example we will use <jsp:include> action tag without parameters. As a result the page will be included in the current JSP page as it is:

index.jsp:

<html>

<head>

<title>JSP Include example</title>

</head>

<body>

<b>index.jsp Page</b><br>

<jsp:include page="Page2.jsp" />

</body>

</html>

Page2.jsp:

<b>Page2.jsp</b><br>

<i> This is the content of Page2.jsp page</i>

Example 2: Use of <jsp:include> along with <jsp:param>:

index.jsp:


Iím using <jsp:include> action here along with <jsp:param> for passing parameters to the page which we are going to include.

<html>

<head>

<title>JSP Include example with parameters</title>

</head>

<body>

<h2>This is index.jsp Page</h2>

<jsp:include page="display.jsp">

<jsp:param name="userid" value="alok sharma" />

<jsp:param name="password" value="alok sharma" />

<jsp:param name="name" value="alok sharma" />

<jsp:param name="age" value="28" />

</jsp:include>

</body>

</html>

display.jsp

<html>

<head>

<title>Display Page</title>

</head>

<body>

<h2>Hello this is a display.jsp Page</h2>

UserID: <%=request.getParameter("userid") %><br>

Password is: <%=request.getParameter("password") %><br>

User Name: <%=request.getParameter("name") %><br>

Age: <%=request.getParameter("age") %>

</body>

</html>

Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!