Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    JSP - JSTL Core <c:import> Tag

    c:import is similar to JSP 'include', which has an additional feature of using absolute URL to include the content of any resource within the server or from a different server to the current JSP page.

    <c:import> Tag Syntax

    Syntax:

    <c:import url="relative_url"/>

    <c:import> Tag Attributes

    Attribute Required Default Description
    url Yes None The URL of the resource to be imported
    context No Current application The context specifies the name of an external resource when accessing a relative resource using a relative path.
    charEncoding No ISO-8859-1 The character encoding used for the imported data.
    var No Print to page The name of the variable to store the imported content.
    scope No Page The variable scope.
    varReader No None Optional variables for providing java.io.Reader object.

    <c:import> Tag Examples

    Here is an example where it imports the content of another resource specified in the url attribute of the '<c:import>' tag. The Imported content will be stored in a variable called 'info'; then it will print on the next line using the '<c:out>' tag.

    Example:

    <%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title> Example of core-import tag </title>
    </head>
    <body>
        <c:import var="info" url="//www.w3schools.in" charEncoding="UTF-8" />
        <c:out value = "${info}"/>
    </body>
    </html>

    Output:

    The above example will fetch the entire source code from w3schools.in and store in a variable name "info" which will eventually be printed.

    If you're importing content from the same web app, you don't need a full URL; you need the URI relative to the web app root.

    Example:

    <c:import url="/menu.jsp" charEncoding="UTF-8" />  


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.