Lead servlet 1.6

It is a Java servlet allows you to preprocess HTTP requests. For example you can collect statistics about requests, add new parameters etc. The idea is very simple: you can replace actual URL's in your hyperlinks with this servlet and pass the original URL as a parameter. E.g. when you display advertising you may put a reference to this servlet instead of the direct reference to the target URL:

1. The original hyperlink:
 


<a href="http://www.merchant.com"><img src="merchant.gif"></a>

2. The modified hyperlink:
 


<a href="http://your_host/servlet/LeadServlet?http://www.merchant.com"><img src="merchant.gif"></a>

Here we are passing the original (target) hyperlink as a parameter for LeadServlet.

Servlet may save visitors data and redirect the source request to the target URL. So it could be useful for example when you implement some advertising or tracking systems. Or you can implement for example load balancing system (LeadServlet may pass requests to the another server), or simply hide the actual location of your data etc.

How to use it:

a) copy leadPackage.jar into your WEB-INF/lib directory.

b) define LeadServlet in your web.xml file. You can set an initial parameter for this servlet switches on stats collection. Parameter name is log. With this parameter servlet will automatically collect the statistical data about requests. This parameter describes a location for your log file (files):
 


    <servlet>
     <servlet-name>LeadServlet</servlet-name>
     <servlet-class>com.jsos.lead.LeadServlet</servlet-class>
    <init-param>
    <param-name>log</param-name>
    <param-value>path_to_your_log_file (directory)</param-value>
    </init-param>
    </servlet>

c) define a mapping:
 


    <servlet-mapping>
     <servlet-name>LeadServlet</servlet-name>
     <url-pattern>/servlet/LeadServlet</url-pattern>
    </servlet-mapping>

As a value for log parameter you may set any existing directory on your server. Log file (files) will be created within this directory automatically. File name will be selected according to the template: ddmmyyyy.txt where dd is current day, mm is current month and yyyy is current year.

Alternatively you may set a path to your log file. In this case all data will be collected within the same file.

Log file is a text file with tab separated values. Each line contains:
date, IP address, target URL, protocol, visitor's browser, referer page, visitor's charset, visitor's encoding, visitor's language (locale).

Without this parameter (log) servlet does not collect the stats.

The target URL could be passed as a query parameter:
 

http://host/servlet/LeadServlet?http://target_site.com

The target URL could be described as an initial parameter also. Parameter name is target:
 


    <servlet>
    <servlet-name>LeadServlet</servlet-name>
    <servlet-class>com.jsos.lead.LeadServlet</servlet-class>
    <init-param>
    <param-name>log</param-name>
    <param-value>path_to_your_log_file (directory)</param-value>
    </init-param>
    <init-param>
    <param-name>target</param-name>
    <param-value>your_target_url</param-value>
    </init-param>
    </servlet>

If the original (target) URL starts with http then LeadServlet will redirect the request. Otherwise servlet assumes the local resource and forward the request. So you can for example forward the requests to your JSP files (for the preprocessing) and redirect (or even terminate) request later there. In case of forwarding LeadServlet saves the original (target) URL in the request scope attribute originalUrl. So you can use this info in your JSP's for example.

    For downloading:   leadPackage.jar

 © Coldbeans Software     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: