<%@ 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的动态标签、静态包含和动态包含的区别