(1) Page (i.e. page range, which only applies to the current page) is empty if it is on other pages

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<! DOCTYPEhtml>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>The four scopes of JSP</h1><% //page scope pagecontext.setAttribute ("name", "zhang SAN "); //request scope request.setAttribute("name"," li Si "); //session scope session.setAttribute("name"," king "); // Application scope application.setAttribute("name"," zhao liu "); % ><h1>Current page gets the value</h1>
<%=pageContext.getAttribute("name")%></br>
<%=request.getAttribute("name")%></br>
<%=session.getAttribute("name") %></br><%=application.getAttribute("name") %> <% forward to demo2.jsp request.getRequestDispatcher("/demo1/demo2.jsp").forward(request,response); % ></body>
</html>
Copy the code

The results after running are as follows:(2) Request redirect demo2.jsp to demo2.jsp instead

<a href="/demo/demo1/demo2.jsp">jump</a>
Copy the code

The resultsAfter the jumpThis value cannot be passed down because it is passed by hyperlink. Therefore, the request is Null.Close the browser or switch to another page:In this case, a new session is opened, so the value of session is null. This scope is the largest scope and can be used anywhere. Unless you shut down the server. Therefore, the four scopes are page< Request <session<application.