Billing Filter ver. 1.6


This is a Java servlet filter (as per Servlet API 2.3). This filter lets you calculate resource usage statistics for your users. BillingFilter counts for the each session three parameters: how many requests have been proceeded, how many bytes have been transferred to user and how many milliseconds of processor time have been spend for those requests. So you may use this filter for some billing system, especially for some wireless applications.

How to use it:

a) download billflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml.
 


<filter>
  <filter-name>billingFilter</filter-name>
  <filter-class>com.cj.billing.billingFilter</filter-class>
</filter>

c) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>billingFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

in this case filter will be on for each your .jsp file

And now when you invoke any .jsp page: http://your_host/your_page.jsp billingFilter will put three parameters into session scope. Their names are requests_counter, bytes_counter and milliseconds_counter. And all the data will be saved as String's. So in your jsp pages you may request them through session.getAttribute() call. For example the following code prints current data (they do not exist for the initial request):
 


<% if (!session.isNew()) { %>
Requests: <%=session.getAttribute("requests_counter")%>
Time (seconds): <%=0.001*Long.parseLong( (String)session.getAttribute( "milliseconds_counter" ))%>
Bytes: <%=session.getAttribute("bytes_counter")%>
<% } %>

Also you may exclude some of your files from the processing. Initial parameter exclude contains a commas separated list of files excluded from the processing.

   For downloading:
    Filter:  billflt.jar
 

 ©  Coldbeans     Comments?

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

Also in JSOS: