JSP三大指令之include

1.作用:包含其他文件,提高代码的可重用程度。

  • 与RequestDispatcher的include方法功能相似,但RequestDispatcher的include是动态包含,在运行时合并两个servlet的响应内容。
  • <%@include ... %>是静态包含,在jsp编译成java文件时完成包含,然后再生成class文件,再执行。

2.格式:<%@ include file="xxx.jsp" %>

3.示范:

在index.jsp文件中包含其他两个独立的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>首页</title>
</head>
<body>
<center>
  <%@include file="head.jsp" %>
  <%@include file="content.jsp" %>
</center>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_38861828/article/details/85336260
今日推荐