BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

JSP include action Tag

Last Updated: July 1, 2024 by Chaitanya Singh | Filed Under: JSP tutorial

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>

Output:

Content of Page2.jsp has been appended in the index.jsp.

IncludeAction-output

Example 2: <jsp:include> with parameters

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="Chaitanya" /> 
<jsp:param name="password" value="Chaitanya" /> 
<jsp:param name="name" value="Chaitanya Pratap Singh" /> 
<jsp:param name="age" value="27" /> 
</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>

Output:

As you can see that the content of display.jsp has been included in index.jsp. Also, the parameters we have passed are displaying correctly in the included page.

include-action-with-parameters-output

Let us know if you have any doubts and questions regarding the topic. We will be happy to assist you!!

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Include Directive in JSP
  3. Java Server Pages (JSP) Life Cycle
  4. Difference between include directive and include tag in JSP
  5. Session Implicit Object in JSP with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap