Detailed description of Application Usage in JSP Programming

Source: Internet
Author: User

Jsp (the preferred choice for SUN enterprise-level applications) has Scope settings in UseBean when calling the Javeabean command. Generally, there are Application session pages and other settings, and page indicates each Page.

This is generally used to re-generate a new usean object in usebean. If multiple jsp (preferred for SUN Enterprise Applications) programs share data, you can use

Session

The application means that the javabean will always exist. Compared with the session, the application is relative to the application.

In general, a user has a session and disappears as the user leaves, while the application always exists, similar

A servlet program is similar to the global variable of the entire system and has 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

This is the preferred page for jsp (SUN enterprise-level applications), and M is the middleware Javabean.

However, with the improvement and promotion of jsp (the preferred choice for SUN enterprise-level applications) functions, there is a trend of replacing servlet, in practice, we use jsp (the first choice for SUN Enterprise applications ).

Jsp (the first choice for SUN Enterprise Applications) is used to replace servlet, especially its control functions.

In fact, this control function is encapsulated in a Javabean. jsp (preferred for SUN Enterprise Applications) uses scope = application to call this Javabean.

The javabean with control functions is similar to the servlet resident memory and interacts with various background middleware operations.

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

Directory category. The home page program reads tree data from the database and expands the data to the home page. This function is encapsulated in Javabean.

Then, when the homepage jsp (the preferred choice for SUN enterprise-level applications) calls this Javabean, it uses scope = application and then uses the tree data buffer algorithm. In this way, multiple

When users access the home page at the same time, the home page jsp (the preferred choice for SUN Enterprise Applications) 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 (the preferred choice for SUN Enterprise Applications) has a high access volume, you should spend more time optimizing it.

Database Connection Buffer


<Jsp (preferred for SUN Enterprise Applications): useBean id = "cods"
Class = "Oracle (large website database platform). jdbc. pool. Oracle (large website database platform) ConnectionCacheImpl"
Scope = "application"/>

<Event: application_OnStart>
<%
Cods. setURL ("jdbc: Oracle (large website database platform): thin: @ HOST: PORT: SID ");
Cods. setUser ("scott ");
Cods. setPassword ("tiger ");
Cods. setStmtCache (5 );
%>
</Event: application_OnStart>

<% @ Page import = "java. SQL. *, javax. SQL. *, Oracle (large website database platform). jdbc. pool. *" %>
<! ----------------------------------------------------------------
* This is a assumerver Page that uses Connection Caching over
Application
* Scope. The Cache is created in an application scope in
Globals. jsa file.
* Connection is obtained from the Cache and recycled back once
Done.

--------------------------------------------------------------------!>
<HTML>
<HEAD>
<TITLE>
ConnCache jsp (preferred for SUN Enterprise applications)
</TITLE>
</HEAD>
<Body bgcolor = EOFFFO>
<H1> Hello
<% = (Request. getRemoteUser ()! = Null? "," +
Request. getRemoteUser (): "") %>
! I am Connection Caching jsp (preferred for SUN Enterprise applications ).
</H1>
<HR>
<B> I get the Connection from the Cache and recycle it back.
</B>
<P>
<%
Try {
Connection conn = cods. getConnection ();
Statement stmt = conn. createStatement ();
ResultSet rset = stmt.exe cuteQuery ("SELECT ename, sal" +
"FROM scott. emp order by ename ");
If (rset. next ()){
%>
<Table border = 1 BGCOLOR = "C0C0C0">
<Th width = 200 BGCOLOR = "white"> <I> Employee Name </I> </TH>
<Th width = 100 BGCOLOR = "white"> <I> Salary </I> </TH>
<TR> <td align = CENTER> <% = rset. getString (1) %> </TD>
<Td align = CENTER >$ <% = rset. getDouble (2) %> </TD>
</TR>
<% While (rset. next ()){
%>
<TR> <td align = CENTER> <% = rset. getString (1) %> </TD>
<Td align = CENTER >$ <% = rset. getDouble (2) %> </TD>
</TR>
<%}
%>
</TABLE>
<%}
Else {
%>
<P> Sorry, the query returned no rows! </P>
<%
}
Rset. close ();
Stmt. close ();
Conn. close (); // Put the Connection Back into the Pool
} Catch (SQLException e ){
Out. println ("<P>" + "There was an error doing the query :");
Out. println ("<PRE>" + e + "</PRE>
<P> ");
}
%>
</BODY>
</HTML>

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.