Java servlet lets you display rotated banners. You can simply set this servlet as an <img> tag attribute in your html-file. A very compact solution for advertising support in your web applications. How to use it: a) copy bannerPackage.jar into your WEB-INF/lib directory. b) define BannerServlet in your web.xml file:
<servlet> <servlet-name>BannerServlet</servlet-name> <servlet-class>com.jsos.banner.BannerServlet</servlet-class> </servlet> c) define a mapping:
<servlet-mapping> <servlet-name>BannerServlet</servlet-name> <url-pattern>/servlet/BannerServlet</url-pattern> </servlet-mapping> In order to use servlet you have to prepare a text configuration file. This file describes
your pictures (banners), how to show them etc. Configuration file will be passed to servlet as a parameter
or as an initial parameter. So there are two basic forms for usage:
a) http://your_host/servlet/BannerServlet?config_file or http://your_host/sevlet/BannerServlet?config=config_file or you may describe config_file as an initial parameter for servlet (parameter name is config)
in your web.xml file:
<servlet> <servlet-name>BannerServlet</servlet-name> <servlet-class>com.jsos.banner.BannerServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>path_to_your_configuration_file</param-value> </init-param> </servlet> and use servlet in this form:
http://your_host/servlet/BannerServlet So in your HTML file you will have some like this:
<img src="http://your_host/servlet/BannerServlet?config_file" width=125 height=125> Such way you can just display different images. b) you can set own redirection URL for the each picture. In this
case your configuration must have files description (see below) and servlet
requires more parameters:
<a href="http://your_host/servlet/BannerServlet?config=your_config_file&mode=2"> <img src="http://your_host/servlet/BannerServlet?config=your_config_file&mode=1" width=468 height=60></a> Such way you can support standard advertising banners c) you can have more than one advertising banner
on the page. In this case just add to the each entry the parameter id=some_unique_integer_value.
These values must be unique within your page. So, for example the first
banner could be be described as:
<a href="http://your_host/servlet/BannerServlet?config=your_config_file&mode=2&id=1"> <img src="http://your_host/servlet/BannerServlet?config=your_config_file&mode=1&id=1" width=468 height=60></a> and the second is:
<a href="http://your_host/servlet/BannerServlet?config=your_config_file&mode=2&id=2"> <img src="http://your_host/servlet/BannerServlet?config=your_config_file&mode=1&id=2" width=125 height=125></a> If you are using an intial parameter, than just remove config= part from URL. E.g.:
<a href="http://your_host/servlet/BannerServlet?mode=2&id=2">
Configuration file is a text file describes servlet's settings. You can save this file anywhere on your server. Configuration file has got free format, but description of any parameter must starts with the appropriate reserved word on the new line. Empty lines and any line starts with # or // are ignored. Current version supports the following list of parameters: # dir. Base directory for your banners. Servlet will output on the round-robin
schema
# describe URL's for the redirection (target sites) in the form of:
# how to rotate banners.
# Logging # directory for log files
or # file name
Log files You can describe an existing directory for log files on your server. In this case servlet will create two log files per day. File names are ddmmyyyyv.txt and ddmmyyyyc.txt Where dd is a day, mm is a month and yyyy is a year. E.g. for Dec 18 2010 files are 18122010v.txt and 18122010c.txt Alternatively you may set some generic file name. E.g. in your config set:
IP address date picture file referer field user agent redirection (for *c.txt files only) How to rotate images without page reloading You can use JavaScript for this. For example, this code rotates banners after 3 seconds:
<img src="http://your_host/servlet/BannerServlet?config_file" width=125 height=125 name="pic1"> <script language="JavaScript"> function swap() { document.images['pic1'].src='http://your_host/servlet/BannerServlet?config_file'; setTimeout('swap()',3000); } setTimeout('swap()',3000); </script> Notes: 1. Banner's configuration file can be saved anywhere on your server. E.g. if you are using BannerServlet?config line we assume this file is saved under the root (docBase) directory of your servletrunner. But you can of course always use the full path for setting config file location: BannerServlet?/home/users/my_file (or BannerServlet?c:\users\my_file) 2. Base directory is any existing directory (with banner files) on your server. 3. Evaluation version supports up to 3 banners per configuration file
for downloading: servlet: bannerPackage.jar See also JSOS - the largest collection of servlets and filters.
|
Also in Coldtags:
|