JSP的九大内置/隐式对象、jsp的动态标签、静态包含和动态包含的区别(页码JSP2)

59 篇文章 0 订阅
50 篇文章 0 订阅

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	aaaaaaaaaaaaaaaaaaaaaaaa
	<%
		out.write("bbbbbbbbbb");
		response.getWriter().write("cccccccccccc");
	%>
	<%="ddddddddddddddddddd" %>

</body>
</html>

在这里插入图片描述

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<% 
		//使用pageContext向request域存数据
		request.setAttribute("name","zhangsan");
		pageContext.setAttribute("name", "sunba");
		pageContext.setAttribute("name","lisi",PageContext.REQUEST_SCOPE);
		pageContext.setAttribute("name","wangwu",PageContext.SESSION_SCOPE);
		pageContext.setAttribute("name","tianqi",PageContext.APPLICATION_SCOPE);
	%>
	
	<%=request.getAttribute("name") %>
	<%=pageContext.getAttribute("name",PageContext.REQUEST_SCOPE) %>
	<%=pageContext.getAttribute("name",PageContext.SESSION_SCOPE) %>
	<%=pageContext.getAttribute("name",PageContext.APPLICATION_SCOPE) %>
	
	<!-- findAttribute会从小到大搜索域的范围中的name,如果找到了就不往下继续找了 -->
	<!-- pageContext<request<session<application -->
	<%=pageContext.findAttribute("name") %>
	
	<%
		pageContext.getRequest();
		pageContext.getOut();
	%>
</body>
</html>

在这里插入图片描述
在这里插入图片描述
动态包含
include1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
		<h1>this is include1</h1>
		<!-- 动态包含include2 -->
		<jsp:include page="/include2.jsp"></jsp:include>
</body>
</html>

include2.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<h1>this is include2</h1>
</body>
</html>

静态包含
include_1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<h1>this is include1 page</h1>
	<!-- 静态包含include2 -->
	<%@ include file="/include_2.jsp" %>
</body>
</html>

include_2.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<h1>this is include2 page</h1>
</body>
</html>

静态包含编译后是两个html页面拼接而成的
在这里插入图片描述
动态页面编译后不会在一个一面内拼接另一个页面,而是翻译成include语句
include1.jsp
在这里插入图片描述
include2.jsp
在这里插入图片描述
在这里插入图片描述
使用jsp:forward完成转发
forward1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<jsp:forward page="/forward2.jsp"></jsp:forward>
</body>
</html>

forward2.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<h1>xxxxxxxxxxxxx</h1>
</body>
</html>

(页码JSP1)JSP技术、脚本和注释、page\include\taglib指令
(页码JSP2)JSP的九大内置/隐式对象、jsp的动态标签、静态包含和动态包含的区别

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值