JSP Page, Request, Session, Application

xiaoxiao2021-03-06  70

Application and Session are relatively simple, here mainly illustrate the scope of REQUEST and PAGE.

Application: Global action range, the entire application sharing, is the same webApp share in the deployment file, the lifecycle is: the application starts to stop.

Session: Session Scope, when the user first accesses, generate a new session, and later the server can remember this session state. Lifecycle: Session timeout, or server-side enforcement to invalidate session.

Request: Request a scope, is a request for the client.

Page: A JSP page.

The above scope is made smaller and smaller, the life cycle of Request and Page is short, and the difference between them is: A Request can contain multiple Page Pages (including, Forward, and Filter). Lift a simple example:

JSP1.jsp

JSP2.jsp

Running jsp1.jsp can display data normally because the scope is request, which is equivalent to calling the request.setttribute () method,

The JSP2 page will get this bean via Request.getaTribute. If you change the request to Page, you will throw NullPointeredExceptiin.

A request can span several JSP (include and forward) and servlets (such as filter). However, there is a difference between you need to pay attention to it.

and <% @ include%>. If the is changed <% @ include file = "jsp2.jsp"%>, even if scope is Page is also Correct, <% @ include%> is compiled, is runtime. The former is equivalent to macro, compiling, the latter is equivalent to the function, and returns when running.

转载请注明原文地址:https://www.9cbs.com/read-121038.html

New Post(0)