Jsp counter creation Manual (1)

Source: Internet
Author: User

Counters are essential to websites. Don't underestimate them. Every time the webmaster looks at the rapid growth of numbers on a small counter, it feels really good. In the past, we used cgi and asp to write counters. There are many articles in this regard. Here, we will use the popular jsp technology to demonstrate how to make a counter.

Two files are used. The test. jsp file is used to run in the browser. counter. java is a small java bean program in the background to read the counter value and write the counter value. For the storage of the counter, We have stored a file named lyfcount.txt.

The following is the detailed program code (put test. jsp to the web directory, and put counter. java to the class directory ):
// Test. jsp file

<% @ Page contentType = "text/html; charset = gb2312" %>
<HTML>
<HEAD>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "GENERATOR" CONTENT = "Oracle JDeveloper">
<TITLE>
Counter demo
</TITLE>
</HEAD>
<BODY>
<! -- Create and call bean (counter) -->
<Jsp: useBean id = "counter" class = "counter" scope = "request">
</Jsp: useBean>
<%
// Call readfileenders of the counterobject to read the count in lyfcount.txt.
String cont = counter. ReadFile ("/lyfcount.txt ");
// Call the readfilecounter of the counterobject to add the counter to the lyfcount.txt file.
Counter. WriteFile ("/lyfcount.txt", cont); %>
You are the <font color = "red"> <% = cont %> </font> visitor
</BODY>
</HTML>

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.