Installation

Please follow the subsequent steps to install Servletspy:

  • Obtain the binary distribution of Servletspy supported by your servlet container.
  • Add the net.sourceforge.servletspy-<version>.jar file to the WEB-INF/lib folder of your web application.
  • Additional libraries have to be added to the WEB-INF/lib folder. See the Dependencies section for more details. In case you are running a struts-based application only the xstream and the xpp3 library must be added. Otherwise include all libraries to the WEB-INF/lib folder excluding the struts library and the servlet library
  • Within the web.xml deployment descriptor of your web application add the following listener to the appropriate section. Please consult the servlet specification available from Sun to learn more about configuring servlet listeners.
    <listener>
       <listener-class>net.sourceforge.servletspy.config.Loader</listener-class>
    </listener>
  • Put the following line in a footer JSP or in any JSP where the information provided by Servletspy should appear.
    <%
    net.sourceforge.servletspy.Spy.getInstance().process( pageContext );
    %>
  • A standard configuration for Servletspy is part of net.sourceforge.servletspy-<version>.jar file. In case you are not running the widely loved Struts web framework, extract the servlet-spy.xml configuration file from the net.sourceforge.servletspy-<version>.jar archive comment out the struts handlers from the servlet-spy.xml configuration file and put the modified file in the WEB-INF/classes folder of your web application. The following is an example configuration, the actual configuration provided with the Servletspy distribution may slightly differ.
    <?xml version="1.0" encoding="UTF-8"?>
    <servletSpy>
      <description>default net.sourceforge.servletspy configuration</description>
      <spyHandlers>
        
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.std.DebugHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.std.NullHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.std.PrimitivesHandler</handlerClassName>
        </handler>
        
        <!-- J A V A    C L A S S   F I L T E R   -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.ClassFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>CLASSES</name>
              <value>
                java.lang.Class 
                java.lang.ClassLoader 
                java.util.Iterator 
                java.util.Enumeration 
                java.net.URL 
                java.net.URLConnection 
                java.net.URLStreamHandler 
                java.net.FileNameMap 
                java.net.ContentHandler 
                </value>
            </param>
          </handlerParams>
        </handler>
        
        <!-- J A V A    P A C K A G E   F I L T E R S  -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.PackageFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>PACKAGES</name>
              <value>
                java.io
                java.util.logging 
                java.lang.reflect 
                java.lang.ref 
                java.security 
               </value>
            </param>
          </handlerParams>
        </handler>
        
        <!-- A P A C H E   P A C K A G E   F I L T E R S  -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.PackageFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>PACKAGES</name>
              <value> 
                org.apache.naming 
                org.apache.commons.validator 
                org.apache.log4j 
               </value>
            </param>
          </handlerParams>
        </handler>
        
        <!-- E J B -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.ClassFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>CLASSES</name>
              <value> 
                javax.ejb.EJBHome 
                javax.ejb.EJBLocalHome 
                javax.ejb.EJBObject 
                javax.ejb.EJBLocalObject 
               </value>
            </param>
          </handlerParams>
        </handler>
        
        
        <!-- O F B I Z / J I R A -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.ClassFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>CLASSES</name>
              <value> 
                org.ofbiz.core.entity.GenericEntity 
                org.ofbiz.core.entity.model.ModelKeyMap 
                org.ofbiz.core.entity.model.ModelEntity 
               </value>
            </param>
          </handlerParams>
        </handler>
        
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.std.CycleDetectorHandler</handlerClassName>
        </handler>
        
        
        <!-- S E R V L E T  A P I  -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.servlet.PageContextHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.servlet.ServletContextHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.servlet.RequestHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.servlet.SessionContextHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.servlet.ServletInterfacesHandler</handlerClassName>
        </handler>
    
    
        <!-- A P A C H E    C L A S S   F I L T E R   -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.ClassFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>CLASSES</name>
              <value>
                org.apache.struts.util.PropertyMessageResources 
                org.apache.jasper.runtime.BodyContentImpl             
               </value>
            </param>
          </handlerParams>
        </handler>
        
        
        <!-- S T R U T S -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.struts.StrutsHandler</handlerClassName>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.ClassFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>CLASSES</name>
              <value> 
                org.apache.struts.action.ActionMapping org.apache.struts.action.ActionServlet 
                org.apache.struts.upload.DiskFile org.apache.struts.upload.MultipartRequestHandler 
                org.apache.struts.upload.DiskMultipartRequestHandler org.apache.struts.upload.MultipartElement 
                org.apache.struts.upload.MultipartRequestWrapper org.apache.struts.upload.FormFile 
                org.apache.struts.upload.MultipartIterator org.apache.struts.config.ActionConfigMatcher </value>
            </param>
          </handlerParams>
        </handler>
        
        
        <!-- J 2 E E   C O N T A I N E R   P A C K A G E   F I L T E R  -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.filter.PackageFilter</handlerClassName>
          <handlerParams>
            <param>
              <name>PACKAGES</name>
              <value> 
                org.apache.coyote 
                com.ibm.websphere 
                weblogic 
               </value>
            </param>
          </handlerParams>
        </handler>
        
        
        <!-- J A V A   B E A N S -->
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.container.ArrayTransformer</handlerClassName>
          <handlerParams>
            <param>
              <name>MAX_ARRAY_SIZE</name>
              <value>54</value>
            </param>
          </handlerParams>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.container.ListTransformer</handlerClassName>
          <handlerParams>
            <param>
              <name>MAX_LIST_SIZE</name>
              <value>54</value>
            </param>
          </handlerParams>
        </handler>
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.container.MapTransformer</handlerClassName>
          <handlerParams>
            <param>
              <name>MAX_MAP_SIZE</name>
              <value>54</value>
            </param>
          </handlerParams>
        </handler>
        
        <!-- W A R N I N G: This handler may cause a lot of trouble,
                        so comment in the handler when you really know what you are doing 
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.container.DynamicProxyTransformer</handlerClassName>
          <handlerParams>
            <param>
              <name>SKIP_COLLECTIONS</name>
              <value>TRUE</value>
            </param>
          </handlerParams>
        </handler>
        -->
        
        <handler>
          <handlerClassName>net.sourceforge.servletspy.handler.container.BeanTransformer</handlerClassName>
        </handler>
        
      </spyHandlers>
    </servletSpy>
  • Restart your web application and point your browser to the URL of the application. There we are. All pages where you have included the JSP scriptlet should provide similar information as shown in the sample. You may click on the tree elements to expand or collapse subtrees.
  • Servletspy is using reflection and introspection to generate the HTML representation. There might be some problems in case your application is using runtime generated classes, e.g. Hibernate extended domain classes. In this case you may add an additional package filter within the configuration to filter out the appropriate packages. In case you feel familar with the IContextHandler API you may also provide your own strategy to handle the classes causing the trouble.
    <handler>
      <handlerClassName>net.sourceforge.servletspy.handler.filter.PackageFilter</handlerClassName>
      <handlerParams>
        <param>
          <name>PACKAGES</name>
          <value> 
    <!-- add your packages here-->
          </value>
        </param>
      </handlerParams>
    </handler>

Please feel free to contact me in case of problems setting up Servletspy. Have fun.