Application of JSP tutorial--application

Source: Internet
Author: User
Tags count integer
application|js| Tutorial

Application of JSP tutorial--application

In the previous article we talked about using session in JSP to save private information for each user, but sometimes the server needs to manage parameters for the entire application so that each customer gets the same parameter value. What should you do in JSP? Like the session, the JSP uses the Application object, and the method of operation is the same as the session "Times New Roman".

Its APIs are used as follows:

Application. setattribute ("Item", Itemvalue); Set an Application variable

Integer i= (integer) application.getattribute ("ItemName"); Get//item

A simple example of the number of online statistics is given to illustrate the application of application (where leave is not considered), init.jsp (initialization), count.jsp (total number of statistics and output).

init.jsp
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<body bgcolor= "#FFFFFF" >
<%
Application.setattribute ("Counter", new Integer (0));
Out.println (Application.getattribute ("Counter"));
%>
</BODY>
</HTML>
count.jsp
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<body bgcolor= "#FFFFFF" >
<%
Integer i= (integer) Application.getattribute ("Counter");
I=new Integer (I.intvalue () +1);
Application.setattribute ("Counter", I);
Out.println ((Integer) Application.getattribute ("Counter"));
%>
</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.