JSTL c:import Core Tag

The JSTL <c:import> Core Tag is used to include the content of other resource at a specific position in the current jsp. It works like include action but the difference is that it can work on relative as well as absolute url while include action can work only on relative url.

Syntax:

<c:import var="varName" url="relUrl/absUrl"/>

c:import tag attributes:

AttributeDescriptionRequired
urlURL to retrieve and import into the page.Yes
context/ followed by the name of a local web application.No
charEncodingCharacter set to use for imported data.No
varName of the variable to store imported text.No
scopeScope of the variable used to store imported text.No
varReaderName of an alternate variable to expose java.io.Reader.No

Example:

test.jsp

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

showInfo.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
This is a c:import JSTL core tag example.

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 37
 
Download this example.
 
Next Topic: JSTL c:forEach Core Tag with example.
Previous Topic: JSTL c:choose , c:when and c:otherwise Core Tags with example.

 

Content Protection by DMCA.com
Please Share