动态包含(<jsp:include>)
来源:互联网 发布:淘宝影响权重的因素 编辑:程序博客网 时间:2024/05/17 09:14
动态包含(<jsp:include>)
使用<jsp:include>指令可以完成动态包含的操作,与使用JSP指令中的include实现的静态包含不同,动态包含语句可以自动区分被包含的页面是静态还是动态。
如果被包含的页面是静态页面,则与静态包含相同,把文件插入后与原来的JSP文件合并成一个新的JSP页面;如果被包含的页面是动态页面,则可以进行动态的处理,然后在将处理后的结果包含进来。
动态包含语法:
n 不传递参数:
<jsp:includepage="{要包含的文件路径|<%表达式%>}"flush="true|false" />
n 传递参数
<jsp:includepage="{要包含的文件路径|<%=表达式%>}"flush="true|false">
<jsp:paramvalue="参数内容"name="参数名称"/>
……可以向包含页面传递多个参数
</jsp:include>
注释:以上语法中,flush属性由于设置是否在缓冲区满了就将内容输出。可选值有true和false,默认值为true。
例1:不传递参数包含3个页面
定义包含页:
<%@ page language="java"contentType="text/html"pageEncoding="GBK"%>
<html>
<head>
<title>jsp:include</title>
</head>
<body>
<h1>动态包含操作</h1>
<jsp:includepage="test.html"/>
<jsp:includepage="test.jsp"/>
<jsp:includepage="test.inc"/>
</body>
</html>
定义test.html页面
<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>test.html</title>
</head>
<body>
thisis test.html file!
</body>
</html>
定义test.jsp页面
<%@ page language="java"contentType="text/html" pageEncoding="GBK"%>
<!DOCTYPEhtmlPUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1">
<title>test.jsp</title>
</head>
<body>
thisis test.jsp file!
</body>
</html>
定义test.inc页面
This is test.inc file!
结果为:
例2:传递参数包含
定义被包含页info.jsp:
<%@ page language="java"contentType="text/html"pageEncoding="GBK"%>
<html>
<head>
<title>info</title>
</head>
<body>
参数1name:<%=request.getParameter("name")%><br>
参数2password::<%=request.getParameter("password")%>
</body>
</html>
定义包含页test.jsp,并传递参数name和password:
<%@ page language="java"contentType="text/html"pageEncoding="GBK"%>
<html>
<head>
<title>test</title>
</head>
<body>
<% String password="123456" ;%>
<jsp:includepage="info.jsp">
<jsp:paramvalue="test"name="name"/>
<jsp:paramvalue="<%=password%>"name="password"/>
</jsp:include>
</body>
</html>
运行结果为:
在实际的开发中,相对于使用JSP指令中的include实现的静态包含,经常使用的是动态包含,因为动态包含可以减少错误(变量重复错误)的产生,可以传递参数。
- 动态包含(<jsp:include>)
- JSP 之 动态包含 <jsp:include />
- 玩转Web之Jsp(一)-----jsp中的静态包含(<%@include file="url"%>)与动态包含(<jsp:include>)
- <jsp:include>动作和include指令的区别/动态包含和静态包含的区别
- JSP指令--include指令(静态包含)
- jsp与include包含
- 在一个jsp页面使用include动态包含servlet
- jsp_ include动态包含
- JSP包含(include指令与include标签)
- JSP 之 静态包含 <%@ include %>
- 实现JSP的继承(动态include)
- include:静态包含和动态包含
- include静态包含和动态包含
- jsp动态包含,静态包含
- jsp静态包含动态包含
- jsp的动态包含
- JSP动态静态包含
- jsp中静态include与动态include
- 公网IP和私网IP
- layer弹窗插件comfirm()的坑
- 怎样将css中的颜色转化为rgba
- Linux 下安装openstf
- python反射机制深入分析
- 动态包含(<jsp:include>)
- Oracle创建触发器详解及例子
- Java中Synchronized的用法
- JAVA 文件IO简单总结
- SQL语句跟部分执行顺序
- 取消ListView的点击效果
- 完美解决安卓滑动删除 以及下拉刷新的事件冲突
- linux运维经验总结
- linux 修改的文件在掉电时会损坏的分析与处理