JSP tutorial-application Application

Source: Internet
Author: User

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");
%>

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.