<c:import>标签的文件混合和代码混合使用

/JavaWeb30day/WebContent/ch09/imported.txt

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Import标签使用</title>
</head>
<body>
<!--
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:out value="Import标签使用"></c:out>
-->

<c:out value="Import标签使用"></c:out>
<b style="color: purple">被导入的import文件</b>

</body>
</html>

/JavaWeb30day/WebContent/ch09/imported.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Import标签使用</title>
</head>
<body>
<!-- 
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -->

<c:out value="Import标签使用"></c:out>
<b style="color: purple">被导入的import文件</b>
</body>
</html>

/JavaWeb30day/WebContent/ch09/imported.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Import标签使用</title>
</head>
<body>
<c:out value="Import标签使用"></c:out>
</body>
</html>

/JavaWeb30day/WebContent/ch09/ImportDemo.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Import标签使用</title>
</head>
<body>
<b style="color: red">导入txt文件</b>
<br>
<c:import url="imported.txt" charEncoding="UTF-8"></c:import>
<br>
<br>
<b style="color: red">导入html文件</b>
<br>
<c:import url="imported.html" charEncoding="UTF-8"></c:import>
<br>
<br>
<b style="color: red">导入JSP文件</b>
<br>
<c:import url="imported.jsp" charEncoding="UTF-8"></c:import>
</body>
</html>


http://localhost:8080/JavaWeb30day/ch09/ImportDemo.jsp

结果图:


<jsp:include>和<c:import>最大的差别在于:
前者只能包含和自己在同一个Web application下的文件;
而<c:import>除了能够包含和自己的同一Webapplication的文件外,
也可以包含不同Web application或者其他网站的文件。

猜你喜欢

转载自blog.csdn.net/jake_aaron/article/details/78634086