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.