Use of the Application in Jsp

Source: Internet
Author: User
Jsp calls the Javeabean command UseBean with Scope settings, usually with Application session page and other settings. Page means that each page re-generates a new usean object in usebean. This is generally used, if multiple Jsp programs share data, you can use session
Application means that the javabean will always exist. Compared with the session, the application is relative to the application. Generally, a user has a session and disappears as the user leaves; the application always exists, similar to a servlet program, similar to the "global variable" of the entire system, and there is only one instance.
Control functions in MVC
Therefore, the application feature is suitable for MVC control functions. In general, traditional MVC uses servlet for control functions, V is basically a Jsp page, and M is a middleware Javabean.
However, with the improvement and promotion of Jsp functions, there is a tendency to replace servlet. In practice, Jsp is more used. Sometimes, to save trouble, Jsp is used instead of servlet. especially its control functions.
In fact, this control function is encapsulated in a Javabean. Jsp uses scope = application to call this Javabean. In this way, the javabean with control function is similar to the servlet resident memory, and interact with various background middleware.
Display of "homepage"
In practical applications, we often have multiple users accessing a page at the same time, such as the homepage, which has many functions to run, such as directory classification, the homepage program reads tree data from the database, expands the data, and outputs the data to the homepage. This function is encapsulated in Javabean.
When the homepage Jsp calls this Javabean, it uses scope = application and then uses the tree data buffer algorithm. In this way, when multiple users access the homepage at the same time, the homepage JSp does not need to start the Javabean every time and then read the database repeatedly. Undoubtedly, the speed is greatly improved.
Therefore, if your homepage Jsp has a high access volume, you should spend more time optimizing it.
Database Connection buffer
<Jsp: useBean id = "cods"
Class = "oracle. jdbc. pool. OracleConnectionCacheImpl"
Scope = "application"/>
<Event: application_OnStart>
<%
Cods. setURL ("jdbc: oracle: thin: @ HOST: PORT: SID ");
Cods. setUser ("scott ");
Cods. setPassword ("tiger ");
Cods. setStmtCache (5 );
%>
</Event: application_OnStart>
<% @ Page import = "java. SQL. *, javax. SQL. *, oracle. jdbc. pool. *" %>
<! ----------------------------------------------------------------
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.