(九)包含指令 (JSP学习第二天)
2011-09-26 15:59
429 查看
静态包含:<%@ include file="要包含的文件的路径">
定义三个要包含的文件info.html,info.jsp,info.inc
info.html文件内容:
info.jsp文件内容:
info.inc文件内容:
使用静态包含三个文件:include_demo01.jsp
动态包含:
<jsp:include page="包含的文件"/>
传递参数的:
<jsp:include page="包含的文件">
<jsp:param name="参数名称" value="参数内容"/>
.........
</jsp:include>
用动态包含三个文件:include_demo02.jsp
定义包含文件,并传递参数 include_demo03.jsp
接收传递的参数:receive_param.jsp
开发时用动态包含,可以避免一些不必要的错误,比如变量重复定义
例如:被包含的动态页include.jsp
<%
int x=10;
%>
<h1>include.jsp--<%=x%></h1>
静态包含处理页:include_demo04.jsp
运行时报错,是因为相同的变量重复定义!
动态包含处理页:include_demo05.jsp
定义三个要包含的文件info.html,info.jsp,info.inc
info.html文件内容:
<h1> <font color="red">info.html</font> </h1>
info.jsp文件内容:
<h1> <font color="green"><%="info.jsp"%></font> </h1>
info.inc文件内容:
<h1> <font color="yellow">info.inc</font> </h1>
使用静态包含三个文件:include_demo01.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <h1>静态包含</h1> <%@include file="info.html" %> <%@include file="info.jsp" %> <%@include file="info.inc" %> </body> </html>
动态包含:
<jsp:include page="包含的文件"/>
传递参数的:
<jsp:include page="包含的文件">
<jsp:param name="参数名称" value="参数内容"/>
.........
</jsp:include>
用动态包含三个文件:include_demo02.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <h1>动态包含</h1> <jsp:include page="info.html"/> <jsp:include page="info.jsp"/> <jsp:include page="info.inc"/> </body> </html>
定义包含文件,并传递参数 include_demo03.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% String username="xiaoming"; %> <jsp:include page="receive_param.jsp"/> <jsp:param name="name" value="<%=username%>"/> <jsp:param name="info" value="ceshi"/> </body> </html>
接收传递的参数:receive_param.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <h1>参数一:<%=request.getParameter("name")%></h1> <h2>参数二:<%=request.getParameter("info")%> </body> </html>
开发时用动态包含,可以避免一些不必要的错误,比如变量重复定义
例如:被包含的动态页include.jsp
<%
int x=10;
%>
<h1>include.jsp--<%=x%></h1>
静态包含处理页:include_demo04.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% int x=100; %> <%@ include file="include.jsp"%> </body> </html>
运行时报错,是因为相同的变量重复定义!
动态包含处理页:include_demo05.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%> <html> <head> <title>测试</title> </head> <body> <% int x=100; %> <jsp:include page="include.jsp"/> </body> </html>
相关文章推荐
- Jsp学习page,scriptlet,注释,指令包含,跳转
- JSP学习笔记---包含指令
- 我的jsp学习日记——001:@include(静态包含指令)和jsp:include(动态包含指令)的区别
- C语言学习笔记之 第六讲:头文件源文件以及include包含指令
- JSP基础 指令include 静态包含的页面也要指明pageEncoding
- JSP经典学习笔记(包含各种入门常用语法)
- <jsp:include>动作和include指令的区别/动态包含和静态包含的区别
- JSP初学者教程学习JSP的基本指令
- JSP学习笔记—— jsp中include文件指令乱码的三种解决方案
- JSP基础语法之三:动态、静态两种包含指令
- JSP学习笔记(JSP的三个编译指令,七个动作指令和常用的内置对象)
- Java web重新梳理学习一(JSP的page编译指令)
- Spring学习之使用标签来标记资源(@Component、@Repository、 @Service和@Controller)以及使用方式(包含如何在jsp中使用)
- JSP初学者教程学习JSP的基本指令
- jsp学习之包含——include
- JAVAWEB开发之Session的追踪创建和销毁、JSP详解(指令,标签,内置对象,动作即转发和包含)、JavaBean及内省技术以及EL表达式获取内容的使用
- JSP包含指令
- 重温JSP学习笔记--三大指令九大内置对象
- Java学习笔记之JSP指令和脚本元素