JavaScript log servlet 1.2

It is a Java servlet lets you log data right from your JavaScript code. Actually you can use Ajax for asynchronous transferring data from your JavaScript code to this servlet. Servlet will record them into log file as well as display via own GUI.

How to use it:

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

b) define JSLogServlet in your web.xml file. You can set an optional initial parameter for this servlet. Parameter name is log. This parameter describes an existing directory for your log file (files). By default it will be / (a root directory):
 


    <servlet>
     <servlet-name>jsLog</servlet-name>
     <servlet-class>com.jsos.jslog.JSLogServlet</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>jsLog</servlet-name>
     <url-pattern>/servlet/jsLog</url-pattern>
    </servlet-mapping>

d) download JavaScript file jslog.js and add it to your JSP (HTML) page:
 


<script language="JavaScript" src="jslog.js"></script>

Now in your JavaScript code you can use the following call:
 


jslogInfo(your data)

E.g.: jslogInfo("x="+x); etc. Your data will be logged by the servlet. You can directly run servlet in the browser:
 


http://your_host/servlet/jsLog

and see the logged data in real time.

By default Ajax request will use the following mapping for log servlet: /servlet/jsLog. Alternatively you may pass a path to log servlet as a second parameter for jslogInfo().

Also your JavaScript code can dynamically switch on/off the logging. Use the following Javascript calls:
 


jsLogOn()
and
jsLogOff()

by default the logging is on.

    For downloading:   jslogPackage.jar     JavaScript library: jslog.js

 © Coldbeans Software     Comments?

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

Also in Coldtags & JSOS: