Technical points of JavaBean in JSP and Serlvle

Source: Internet
Author: User
Tags range valid

First, initialization of JavaBean

1, in the JSP

The following procedure is executed in the code in the previous paragraph:
? Look for the javabean of the same ID according to the parameters of scope, if found, jump out of it;
? If not found, an instance is created at the position of the scope parameter and the initialization statement is executed and in;
In other words, if you are sure you want to set the Beanname in the current state of the scope parameter position, avoid using the code like the above, and you should put the statement outside.
2, in the Serlvlet
Package.classname beanname=new package.classname ();
Then place the beanname in a different position;

Ii. location and operation of JavaBean

It is said here that the location of the JavaBean is mainly for different scopeparameter, so it will be discussed here separately.
The JSP servlet reads and writes (the servlet lists only the acquisition or set reference, the setxxx and getxxx that omit the specific attributes)
JSP Servlet
Scope= "Page" Request.pagecontext
Or
Direct reference
Scope= "Request" Request Package.classname beanref= (package.classname) request. GetAttribute ("Beanname");
Or
Request.setattribute ("Beanname", beanref);
Scope= "Session" HttpSession HttpSession session= request.getsession (true);
Package.classname beanref = (package.classname) session.getattribute ("Beanname");
Or
Session.setattribute ("Beanname", beanref);
Scope= "Applicaton" ServletContext package.classname beanref= getservletcontext (). getattribute ("Beanname");
Or
Getservletcontext (). setattribute ("Beanname", beanref);

Third, the specific application

Type Application
Scope= The default setting of "page" in a JSP, similar to a variable instance within a page range.
Scope= "Request" A variable instance within the valid range of a request.
Scope= "Session" within a client access scope variable instances, each access is different.
Scope= "Applicaton" is a variable instance within the scope of the server program, similar to static, valid for each client access.

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.