application and session are relatively simple. The scope of application and page is described here.
application: global scope. The entire application Program is shared, that is, the same webapp in the deployment file is shared, and the lifecycle is: the application starts to stop.
session: indicates the session scope. When a user accesses a session for the first time, a new session is generated, and the server can remember the session status. Life cycle: the session times out, or the server forces the session to fail.
request: Request scope, which is a client request.
page: a JSP page.
the above scope is getting smaller and smaller, and the request and page lifecycles are short. The difference between them is that a request can contain multiple page (include, forward and filter ). For example,
jsp1.jsp
jsp2.jsp
RUN jsp1.jsp to display data normally, because the scope of function is request, it is equivalent to calling request. setattribute () method. The jsp2 page passes the request. getattribute to obtain the bean. if you change the request to page, nullpointereffectioin will be thrown.
a single request can span several JSP (include and forword) and Servlet (such as filter ). however, the difference between
; and <% @ include>. if the preceding is changed to <% @ include file = "jsp2.jsp" %>, even if the scope is page, <% @ include %>; it is included during compilation, and it is included during runtime. the former is equivalent to a macro, which is replaced during compilation, and the latter is equivalent to a function, which is returned at runtime.