Latest web development tutorials

<c:import> 標籤

JSP 標準標籤庫 JSP標準標籤庫

<c:import>標籤提供了所有<jsp:include>行為標籤所具有的功能,同時也允許包含絕對URL。

舉例來說,使用<c:import>標籤可以包含一個FTP服務器中不同的網頁內容。

語法格式

<c:import
   url="<string>"
   var="<string>"
   scope="<string>"
   varRender="<string>"
   context="<string>"
   charEncoding="<string>"/>

屬性

<c:import>標籤有如下屬性:

屬性 描述 是否必要 默認值
url 待導入資源的URL,可以是相對路徑和絕對路徑,並且可以導入其他主機資源
context 當使用相對路徑訪問外部context資源時,context指定了這個資源的名字。 當前應用程序
charEncoding 所引入的數據的字符編碼集 ISO-8859-1
var 用於存儲所引入的文本的變量
scope var屬性的作用域 page
varReader 可選的用於提供java.io.Reader對象的變量

實例演示

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>c:import 标签实例</title>
</head>
<body>
<c:import var="data" url="http://www.w3big.com"/>
<c:out value="${data}"/>
</body>
</html>

以上程序將會打印http://www.w3big.com"頁面的源代碼,您可以自己動手嘗試一下。


JSP 標準標籤庫 JSP標準標籤庫