Beginner JSP, wrote a simple page access counter __jsp

Source: Internet
Author: User

Just a preliminary understanding of the JSP nine objects, such as the ASP simple page program to find data written out should be no problem, but there is a problem has been puzzling me, that is how to deploy JavaBean? In the afternoon to see the tutor, look for information this evening to study a clear, the following simple program although can record the number of visits , but application reboot and restore zero, so also add a data storage function, or forget it, practice practicing, are similar.

<%@ page contenttype= "text/html; charset=gb2312 "%>
<%@ page import= "java.util.*"%>
<%
JSP Example
Simple Counter
Code by Xmaro
%>
<HTML>
<pre>
<%
Integer asum= (integer) application.getattribute ("Sum");
Integer ssum= (integer) session.getattribute ("Sum");
if (asum==null) {
asum=0;
}
if (ssum==null) {
ssum=0;
}
Application.setattribute ("Sum", asum+1);
Session.setattribute ("Sum", ssum+1);
Asum= (Integer) application.getattribute ("Sum");
Ssum= (Integer) session.getattribute ("Sum");
%>
<HR width=62% border=1 align=left><br>
You have visited the number of times is: <%=sSum%> The total amount of visits to the page: <%=aSum%>
</pre>
</BODY></HTML>

Just a preliminary understanding of the JSP nine objects, such as the ASP simple page program to find data written out should be no problem, but there is a problem has been puzzling me, that is how to deploy JavaBean? In the afternoon to see the tutor, look for information this evening to study a clear, the following simple program although can record the number of visits , but application reboot and restore zero, so also add a data storage function, or forget it, practice practicing, are similar.

<%@ page contenttype= "text/html; charset=gb2312 "%>
<%@ page import= "java.util.*"%>
<%
JSP Example
Simple Counter
Code by Xmaro
%>
<HTML>
<pre>
<%
Integer asum= (integer) application.getattribute ("Sum");
Integer ssum= (integer) session.getattribute ("Sum");
if (asum==null) {
asum=0;
}
if (ssum==null) {
ssum=0;
}
Application.setattribute ("Sum", asum+1);
Session.setattribute ("Sum", ssum+1);
Asum= (Integer) application.getattribute ("Sum");
Ssum= (Integer) session.getattribute ("Sum");
%>
<HR width=62% border=1 align=left><br>
You have visited the number of times is: <%=sSum%> The total amount of visits to the page: <%=aSum%>
</pre>
</BODY></HTML>

The first time on December 28, 2005 3:01 pm published in Donews blog, because Donews blog no longer updated, special forwarding on this.

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.