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 with parameter example

Last Updated: September 10, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

Earlier we have shared how to include a page to another JSP page using include directive and include action tag. We have also discussed the difference between include directive and include action tag. In this post we will see how to pass parameters to included page while using jsp include action tag (<JSP:Include>). In order to pass the parameters we need to use the <jsp:param> action tag.

Example

In this example we are including a JSP page (file.jsp) to the main JSP page (index.jsp) using <jsp:include> action tag. To pass the parameters from index to file page we are using <jsp:param> action tag. We are passing three parameters firstname, middlename and lastname, for each of these parameters we need to specify the corresponding parameter name and parameter value. The same we can extract at the included page using expression language or expression tag & implicit object.

index.jsp

<html>
<head>
<title>JSP include with parameters example</title>
</head>
<body>
<jsp:include page="file.jsp" >
  <jsp:param name="firstname" value="Chaitanya" />
  <jsp:param name="middlename" value="Pratap" />
  <jsp:param name="lastname" value="Singh" />
</jsp:include>
</body>
</html>

file.jsp

${param.firstname}<br>
${param.middlename}<br>
${param.lastname}

Output:

jsp-param-action

As you can see that the included page displayed the parameters values passed from the main page. For displaying the parameters on the file.jsp page, we have used the expression language (${}). However you can also use the following code which is using the JSP expression tag and request implicit object.

<%= request.getParameter("firstname")%>
<%= request.getParameter("middlename")%>
<%= request.getParameter("lastname")%>

That’s all we have for this topic. In the coming post we will discuss how to pass parameters and their values to another page using include directive. Meanwhile if you have any questions, ask the same in the comment section below.

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Java Server Pages (JSP) Life Cycle
  3. Include Directive in JSP
  4. JSP forward action tag
  5. JSP Implicit Objects

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

Comments

  1. Migadde Denis says

    July 27, 2015 at 1:03 PM

    This was really help full please. thank u so much

    Reply

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