>I have written a couple of "baby" servelets, but the process seemed
>slightly tedious.  I noticed that when I was experimenting with server
>side includes, I did not have any mechanism at all for testing my code
>except to do it "live", on my production server...
>
>My normal development technique involves a crude
>WRITE--COMPILE--RUN--DEBUG/REWRITE--ADD FEATURE--COMPILE--RUN--ETC,
>ETC.  Unfortunately, I do not know what servlet development environment
>will let me constantly compile, run and check my code incrementally as I
>normally enjoy doing.  Are there any hints out there for a newbie?  Any
>thoughts, suggestions, or shared experiences would be greatly
>appreciated, and would probably save some serious initial floundering on
>my part!


I write regular servlets and I write filters. I haven't found a great way of
debugging the filters yet, but I have found a good way to do the servlets.
(I don't spend much time on the filters, but I could probably get my method
to work with them too.) My method should work in just about any development
environment, whether it is an IDE or a text editor and make files.

I include a pure Java web server in my project. I currently use Nexus
<http://www-uk.hpl.hp.com/people/ak/java/nexus/>, but there are others out
there. Sun provides a class called ServletRunner or something, but it
doesn't serve HTML files, which I find useful in testing my servlets.
ServletCentral <http://www.servletcentral.com/> has a list of web servers,
some of which are pure Java.

I have a class called ServletTest whose main() method creates an instance of
the web server, registers the servlets, sets the HTML document root
directory and then starts the web server.

I put breakpoints in my servlets, run ServletTest.main() and then open a web
browser and hit my web server at <http://localhost:8002/servlet/MyServlet>.
The debugger stops at the breakpoints just like it would in any application.


Some code from my ServletTest class follows. Hope it helps.

- - - - -

import hplb.nexus.*;
import java.util.*;

public class ServletTest
{
    public static void main( String[] inArgs )
    {
        HttpServer httpd = new HttpServer();
        httpd.setPortNo( 8002 );

        registerServlet( httpd, "/servlet/MyServlet",
"com.mycompany.MyServlet", null );

        httpd.aliases.put( "/", "d:/htdocs/" );
        httpd.start();
    }

    public static void registerServlet


        HttpServer inServer,
        String inServletName,
        String inClassName,
        Hashtable inInitArgs
    )
    {
        GenericServlet servlet = null;

        try
        {
            servlet = inServer.createServlet( Class.forName( inClassName ),
inInitArgs );
            inServer.registerServlet( inServletName, servlet );
        }
        catch ( ClassNotFoundException e )
        {
            System.err.println( e );
        }
    }
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to