1.jsp代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true" isELIgnored="false"%>
<!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>
//执行顺序 page-request-session-application <br>
<% request.setAttribute("name", "zs");%>
<%--<% request.getRequestDispatcher("/public/top.jsp").include(request, response); %>
<% request.getRequestDispatcher("/public/left.jsp").include(request, response); %>
--%>
username:<input type=text value="${name}"><br>
<%request.setAttribute("data", "aaaa");%>
<% String data=(String)pageContext.getAttribute("data", pageContext.REQUEST_SCOPE);
out.write(data);%><br>
<% String data1=(String)pageContext.findAttribute("data");%>
String data=(String)pageContext.getAttribute("data",pageContext.REQUEST_SCOPE);
<% out.write(data1);%>
</body>
</html>
2.程序运行如下:
//执行顺序 page-request-session-application
username:
aaaa
String data=(String)pageContext.getAttribute("data",pageContext.REQUEST_SCOPE); aaaa