The page,request,session,application in JSP

Source: Internet
Author: User
Tags filter include
Application|js|request|session application and session is relatively simple, here is the main description of the request and page scope.
Application: Global scope, the entire application is shared, that is, the same webapp share in the deployment file, the lifecycle is: Application startup to stop.
Session: Sessions scope, when the user first accesses, produces a new session, the server will be able to remember the session state. Lifecycle: The session timed out, or the server side forces the session to fail.
Request: The scope of requests is a request from the client.
Page: a JSP page.
The scope of the above effect is getting smaller, and the life cycle of the request and page is short, and the difference is that a request can contain multiple page pages (Include,forward and filter). For 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"/>
Running jsp1.jsp can display data normally, because the scope is request, equivalent to calling the Request.setattribute () method,
The JSP2 page is request.getattribute to get this bean. If you change the request to page, the Nullpointerexceptioin is thrown.
A request can span several JSPs (include and ForWord) and a servlet (such as filter). But here's one thing to be aware of is the distinction
<jsp:include> <%@ include%&gt if <jsp:include page= "jsp2.jsp"/> to <%@ include file= "jsp2.jsp"% Even if scope is correct for page, the <%@ include%> is compiled with,<jsp:include> included. The former is the equivalent of a macro, a compile-time substitution, the latter equivalent to a function, and a run-time return.


Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.