beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

JSP include action with parameter example

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.

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
  • Declaration tag
  • Expression tag
  • Scriptlets
  • Directives
  • Include Directive
  • Param Directive
  • Exception handling
  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty
  • Implicit Objects
  • Session implicit object
  • Validate session
  • Request implicit object
  • Response implicit object
  • Out implicit object
  • Application implicit object
  • Config implicit object
  • pageContext implicit object
  • Exception implicit object
  • Expression language
  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap