Key Technical Points of JavaBean

Source: Internet
Author: User

Key Points of transferring javaBean in jsp and serlvle

I. initialize javaBean

1. In jsp

The execution process of the previous Code is as follows:

? Search for javabean with the same id according to the scope parameter. If it is found, it jumps out;

? If not found, create an instance at the scope parameter and execute the and mid-initialization statements;

That is to say, if you are sure to set the beanname at the scope parameter location in the current state, avoid using code similar to the above, instead of placing the statement outside.

2. In serlvlet

Package. classname beanname = new package. classname ();

Place beanname in different locations;

Ii. locations and operations of javabean

The storage location of javabean is mainly pointer for different scopeparameter, so we will discuss it here separately.

Jsp servlet read/write method (Servlet only lists the obtained or set reference, and omitted setXxx and getXxx 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 );

Iii. Specific applications

Type Application

Scope = "page" is the default setting in jsp, similar to a variable instance in the page range.

Scope = "request" is a variable instance within the valid range of one request.

Scope = "session" is a variable instance within the client access range. Each access is different.

Scope = "applicaton" variable instances within the scope of the server program, similar to static, are valid for each customer access.

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.