有时候需要在 JSP 页面静态包含一个文件,例如 HTML 文件,文本文件等,这时,可以通过 include 指令来实现,include 具体语法格式如下所示:
<%@ include file="relativeURL" %>
具体Demo如下
(1)include.jsp
(2)data.jsp
(3)启动 Tomcat,打开浏览器
在浏览器中输入:http://localhost:8080/JspDemo/include.jsp
(4)顺便提一下,还有一种东西叫 JSP标签
其中 <jsp:include> 动作标签 它的格式如下
<jsp:include page="relativeURL" flush="true">
顺便附一下 include 指令和 include 标签的区别
本文链接:https://liuyanzhao.com/5132.html
<%@ include file="relativeURL" %>
具体Demo如下
(1)include.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>Insert title here</title>
- </head>
- <body>
- 欢饮您,现在的时间是:
- <%@ include file="data.jsp"%>
- </body>
- </html>
(2)data.jsp
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%
- out.print(new java.util.Date().toLocaleString());
- %>
(3)启动 Tomcat,打开浏览器
在浏览器中输入:http://localhost:8080/JspDemo/include.jsp
(4)顺便提一下,还有一种东西叫 JSP标签
其中 <jsp:include> 动作标签 它的格式如下
<jsp:include page="relativeURL" flush="true">
顺便附一下 include 指令和 include 标签的区别
本文链接:https://liuyanzhao.com/5132.html
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏