JSP tutorial -- Application
In the previous article, we talked about using sessions in JSP to store private information of each user. However, sometimes the server needs to manage parameters for the entire application, this allows each customer to obtain the same parameter value. What should I do in JSP? Like session, JSP uses the application object. The operation method is the same as session "Times New Roman.
Its API usage is as follows:
Application. setattribute ("item", itemvalue); // you can specify an application variable.
Integer I = (integer) application. getattribute ("itemname"); // get // item
The following uses an example to describe how to calculate the number of online users: Application (this case is skipped), init. jsp (initialization), and count. jsp (count and output the total number of online users ).
init. JSP
new document
<%
application. setattribute ("counter", new INTEGER (0);
out. println (application. getattribute ("counter");
%>
count. JSP
new document
<%
integer I = (integer) application. getattribute ("counter");
I = new INTEGER (I. intvalue () + 1);
application. setattribute ("counter", I);
out. println (integer) application. getattribute ("counter");
%>