指令与动作之include动作

本文介绍了JSP中的include动作,包括其语法、参数说明及如何使用。通过示例代码展示了如何将日期显示功能包含到主页面中,并解释了缓冲机制的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

指令与动作之include动作
include动作
统一编译 
语法:<jsp:include  page="URL"  flush="true/false"/>  page表示要包含的页面,flush表示被包含的页面是否从缓冲区中读取,true表示使用缓冲,false表示不使用缓冲,刚开始默认为false。
注释:缓冲器为暂时置放输出或输入资料的内存。缓冲器内资料自储存设备(如硬盘)来,放置在缓冲器中,须待机送至CPU或其他运算设备。缓冲区(buffer)这个中文译意源自当计算机的高速部件与低速部件通讯时,必须将高速部件的输出暂存到某处,以保证高速部件与低速部件相吻合. 后来这个意思被扩展了,成为"临时存贮区"的意思。


代码:
date.jsp
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
    Date d=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
    String s=sdf.format(d);
    out.println(s);
%>

action.jsp
<%@ page language="java" import="java.util.*"  contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'datetest.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  
  </head>
  
  <body>
   <h1>include动作</h1>
   <hr>
  <jsp:include page="date.jsp" flush="false"/>
  </body>
</html>

运行结果:




include指令与动作的区别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值