Application and session are relatively simple. Here we mainly describe the scope of application and page.
Application: global scope of action. The whole application is shared, that is, the same webApp in the deployment file is shared, and the lifecycle is: the application starts to stop.
Session: session scope. When a user accesses a session for the first time, a new session is generated, and the server will be able to 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 scope of the above is getting smaller and smaller, and the lifecycle of requests and pages is short. The difference between them is that a request can contain multiple page pages (include, forward, and filter ). A simple example:
Jsp1.jsp
<Jsp: useBean id = "beanID" class = "xxx. xxx. BeanClass" scope = "request"/>
<Jsp: include page = "jsp2.jsp"/>
Jsp2.jsp
<Jsp: getProperty name = "beanID" property = "sample"/>
Run jsp1.jsp to display data normally, because the scope of the function is request, which is equivalent to calling the request. setAttribute () method,
The jsp2 page obtains the bean through request. getAttribute. If you change the request to page, NullPointerExceptioin will be thrown.
A request can span several JSP (include and forword) and Servlet (such as filter). However, there is a difference to note here.
<Jsp: include> and <% @ include %>. if the preceding <jsp: include page = "jsp2.jsp"/> is changed to <% @ include file = "jsp2.jsp" %>, even if the scope is page, <% @ include %> is included at compilation, and <jsp: include> is included at 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.