JSP學習之include指令

    今天,看視頻自學JSP的include指令,他主要有動態和靜態兩種包含方式,用於在一個JSP頁面裏包含其餘jsp頁面的內容。html

    我本身常式了一下編碼:java

動態包含方式:jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>動態包含,在運行時包含,它包含的每一個jsp都會生成一個servlet</title>
</head>
<body>
<%

	request.getRequestDispatcher("/public/head.jsp").include(request,response);
 %>
<%
	response.getWriter().write("aaaaaaaaaaa");
 %>
<%
	request.getRequestDispatcher("/public/foot.jsp").include(request, response);
 %>
</body>
</html>

靜態包含方式:性能

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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">
<title>include指令(靜態包含,它包含的全部JSP會編譯成一個servlet)</title>
</head>
<body>
<%@include file="/public/head.jsp"%>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<%@include file="/public/foot.jsp" %>
</body>
</html>

兩種包含方式作出的頁面效果是同樣的,可是靜態包含比動態包含性能要好,因此在項目中通常都用靜態包含。同時在使用include指令時候要注意保持html頁面源碼的良好性。ui

相關文章
相關標籤/搜索