Analysis of Java Servlet Construction System

Source: Internet
Author: User

For a business website, the advertising system is essential. A good advertising system is the basis for a stable website revenue. Banner is the vast majority of website advertisements. Therefore, it is very important to develop a banner advertising system. Using Java Servlet, we can easily build our own flag advertising system.

We usually put some pictures on the webpage, set their links to point to the webpage of the AD customer, and then generate the log file to store the browsing count, the IP address of the viewer, and other information, this is the general idea of developing a flag advertising system.

Next, I would like to introduce how to use Java Servlet to build a flag advertising system in combination with a routine. In the following example, you must use the label in your HTML file.

Three methods are used:

1) Banner? Config_file or Banner? Config = config_file

2) You can also set your own Redirection URL for each image. You only need to add the file description in your settings, and the Servlet also needs more description parameters.

3) You can also have multiple flag ads on the same page. You only need to add "id = an integer" to the parameter. This value must be a unique integer on your page!

Some may ask, what is config_file? It is a text file used to describe Servlet settings. You can save this file anywhere on your host. Here we will introduce the parameters. This configuration file has three parameters:

1. dir = some_directory
Explanation: dir is the directory where your banner ad files are stored. The available image formats include JPG, GIF, PNG, and JPEG. This parameter is required; otherwise, an error is reported.

2. bannerfilename = some_url
Explanation: the banner file uses the following format:
Banner.gif = http://www.yesky.com/
Banner.jpg = http://www.yesky.com/

3. log = some_directory_to_store_log_file

Explanation: the directory for storing log files can be any directory on the server. Log file) and format
The Banner system automatically generates two log files every day. The differences are ddmmyyyyv.txtand ddmmyyyyc.txt. The first file stores the browsing banner record, and the second file stores the redirection record. Both files are text files, and each row contains a record. The record format is:
IP address date image file user Proxy Redirection record (only for * c.txt files), fields are separated by spaces.

Banner. java source code:

 
 
  1. Import java. io .*;
  2. Import java. util .*;
  3. Import javax. servlet .*;
  4. Import javax. servlet. http .*;
  5. Public class Banner extends HttpServlet
  6. {
  7. Public Banner (){
  8. }
  9. File: // read the content of the configuration file
  10. Private boolean readConfig (String sConfig, Hashtable hashtable)
  11. {
  12. Try
  13. {
  14. BufferedReaderBufferedreader=NewBufferedReader (new InputStreamReader
    (New FileInputStream (sConfig )));
  15. // Set the buffer to read a configuration file
  16. String sLineInformation1 ;//
  17. While ((SLineInformation1=Bufferedreader. ReadLine ())! = Null)
  18. {
  19. SLineInformation1SLineInformation1= SLineInformation1.trim ();
  20. // Remove spaces from the string
  21. If (sLineInformation1.length ()>0)
  22. // If the length of string sLineInformation1 is greater than zero {
  23. IntI=SLineInformation1. IndexOf ("= ");
  24. }
  25. }

The above is the use of Java Servlet we can easily build our own flag advertising system.

  1. Servlet declaration and mapping replace your Web
  2. HTTP Servlet Application Programming Interface
  3. Java Servlet and Applet comparison
  4. Detailed introduction to MyServlet code
  5. What is ServletResponse?

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.