import tag in JSP Core Tag Library
What is "import" tag in JSP Core Tag Library?
Explanation
The
import tag of the core tag library can be used to include file or content within the application or from outside the web application. This is the main advantage of "<c:import" compared to "jsp:include" tag.
Syntax:
<c:import [url="url"] [context="externalContextPath"]
[var="var"] [scope="page|request|session|application"]
[charEncoding="charEncoding"]>
Optional <c:param> actions
</c:import>
In the above syntax the "url" attribute stores the url, "context" attribute is optional can give a context name that is usually perpended to the url, <c:param is used to customize the parameters needed from file or url. Example :
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>
<p>Use of c:import in jstl</p>
<c:import url="fulldate.jsp"/>
<p>Date displayed from full date.jsp::</p>
</c:import>
Following is the code of "fulldate.jsp" file
<%@page contentType="text/html" import="java.util.*" %>
<p>Current time</p>
<%=new java.util.Date() %>
In the above example we have imported the file "fulldate.jsp" to display the current date value, one can also use "c:<param" to get only specific parameters.