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

JSTL <c:import> Core Tag

Last Updated: November 30, 2013 by Chaitanya Singh | Filed Under: JSTL

JSTL <c:import> tag is used for importing the content from another file/page to the current JSP page.

Syntax:

<c:import var="variable_name" url="relative_url"/>

Here variable_name is a variable which stores the data imported from another url.
relative_url is the address of the file/page which needs to be imported.

Attributes of <c:import>

  • url: It’s mandatory attribute and needs to be mentioned always.
  • var: It is an optional attribute if this is not specified then the imported data will be printed on the current page. For e.g. the statement <c:import url=”/file.jsp” /> would print the data of file.jsp on the client (browser).
  • scope: It is also optional. If we are using var attribute then scope can be used along with it to specify the scope of the data stored in the variable.

Example

This is an page which has some data. We will import this page in index.jsp page.

display.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="Chaitanya"/>
<c:out value="BeginnersBook.com" />
<c:out value="This is just a String" />

index.jsp

Here we are importing the data from display.jsp into a variable mydata and then we are displaying it on browser using <c:out> tag.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title> JSTL c:import Tag Example</title>
</head>
<body>
<c:import var="mydata" url="/display.jsp"/>
<c:out value="${mydata}"/>
</body>
</html>

Output Screen:

c-import-example

Top Related Articles:

  1. JSTL <c:redirect> Core Tag
  2. JSTL <c:set> Core Tag
  3. JSTL <c:out> Core Tag
  4. JSTL <c:remove> Core Tag
  5. JSTL <c:url> Core Tag

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 *

JSTL Core Tags

  • c:out
  • c:set
  • c:remove
  • c:if
  • c:choose
  • c:when
  • c:otherwise
  • c:catch
  • c:import
  • c:forEach
  • c:forTokens
  • c:param
  • c:url
  • c:redirect
JSTL Functions
  • fn:contains()
  • fn:containsIgnoreCase()
  • fn:indexOf()
  • fn:escapeXML()
  • fn:join() & fn:split()
  • fn:length()
  • fn:startsWith()
  • fn:endsWith()
  • fn:substring()
  • fn:substringAfter()
  • fn:substringBefore()
  • fn:trim()
  • fn:toUpperCase()
  • fn:toLowerCase()
  • fn:replace()

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap