JSP-include指令
来源:互联网 发布:淘宝客在哪推广 编辑:程序博客网 时间:2024/06/13 12:03
JSP-include指令
用法:
<%@ include file="路径" %>
a1.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> <h2>a1 Page</h2></body></html>
a2.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> <h2>a2 Page</h2> <%@ include file="/WEB-INF/a1.jsp"%></body></html>
运行:
动态包含和静态包含的区别
静态包含:
a1.jsp
<h2>a2 Page</h2><% String s = "abcd";%><%@ include file="/WEB-INF/a1.jsp"%>
a2.jsp
<h2>a1 Page</h2><%= s %>
运行:
动态包含:
用法:
<jsp:include page="路径"></jsp:include>
a2.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> <h2>a2 Page</h2> <jsp:include page="/WEB-INF/a1.jsp"></jsp:include></body></html>
a1.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> <h2>a1 Page->动态包含</h2></body></html>
运行:
但是如果使用刚才的例子,会出现空指针异常,因为动态包含其实在
底层生成的是两个java文件,而静态包含是一个java文件
动态包含传递参数:
a2.jsp:
<h2>a2 Page</h2><% request.setCharacterEncoding("UTF-8");%><jsp:include page="/WEB-INF/a1.jsp"> <jsp:param value="猴赛雷" name="name"/></jsp:include>
a1.jsp
<h2>a1 Page->动态包含</h2><%= request.getParameter("name") %>
运行:
0 0
- JSP的include指令
- Jsp中的include指令
- JSP include指令
- JSP page、include指令
- JSP中include指令
- jsp中的include指令
- jsp include指令元素
- JSP,include指令ud
- JSP之【include】指令
- JSP中的include指令
- jsp include指令
- JSP include 指令
- JSP的include指令
- jsp include指令标签
- jsp语法-include指令
- JSP页面include指令
- jsp include指令
- jsp include指令元素
- 机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾
- UVA 12658 模拟
- VS2010~VS2013中文注释带红色下划线的解决方法
- 在文章中使用amsmath宏包的原因
- 积跬步至千里系列之十--编译Android源码实践
- JSP-include指令
- java学习笔记-参数的调用
- neuq oj 1047: 谭浩强C语言(第三版)习题6.3 C++
- PyQt4入门教程(3)_菜单栏和工具条
- UVA 12667 模拟
- 基于ARM-contexA9-蜂鸣器pwm驱动开发
- 快速排序
- OpenJudge百炼习题解答(C++)--题4108:羚羊数量-Number Of Antelope
- iOS(学习6) 横竖屏