tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dustin Callaway <DCalla...@hfnweb.com>
Subject RE: SimpleStartup.java fix...
Date Thu, 20 Jan 2000 16:34:53 GMT
Jim,

Register your servlets and provide a URL mapping in the web.xml file within
each context (e.g., /webpages or /examples).

Dustin


-----Original Message-----
From: James Cook [mailto:jimcook@iname.com]
Sent: Thursday, January 20, 2000 9:27 AM
To: tomcat-dev@jakarta.apache.org
Subject: Re: SimpleStartup.java fix...


thanks for the fix.

How do I now tell the Tomcat Webserver where to find my servlets? My former
URL (that worked with JSWDK 1.0.1) is
http://itccd310:8080/servlet/research.servlet.MainServlet. I get a 404 error
with Tomcat.

thanks,
jim

----- Original Message -----
From: Dustin Callaway <callaway@sourcestream.com>
To: <tomcat-dev@jakarta.apache.org>
Sent: Wednesday, January 19, 2000 11:37 PM
Subject: SimpleStartup.java fix...


The following SimpleStartup.java class starts the Tomcat HttpServer from
within a Java application. This allows for servlet debugging from within an
IDE. Many thanks to Jim Rudnicki for the sample code (which I just cleaned
up and simplified). Place this application in the /tomcat directory and run
it from there.


import org.apache.tomcat.server.HttpServer;
import java.net.URL;

/**
 * SimpleStartup starts the Tomcat HttpServer in a Java
 * application to allow for debugging within an IDE.
 */
public class SimpleStartup
{
  public static void main(String[] args)
  {
    try
    {
      HttpServer server = new HttpServer(8080, null, null);

      URL url = resolveURL("webpages");
      server.getContextManager().setDocumentBase(url);

      url = resolveURL("examples");
      server.addContext("/examples", url);

      server.start(); file://start the server
    }
    catch (Exception e)
    {
      System.out.println("Error: " + e);
    }
  }


  private static URL resolveURL(String s) throws Exception
  {
    // if the string contains :/, then we assume that it's a real URL and do
nothing
    if (s.indexOf(":/") > -1)
    {
        return new URL(s);
    }

    // otherwise, we assume that we've got a file name and
    // need to construct a file url appropriatly.
    if (s.startsWith("/"))
    {
      return new URL("file", null, s);
    }
    else
    {
      String pwd = System.getProperty("user.dir");
      return new URL("file", null, pwd + "/" + s);
    }
  }
}


That's it. Register your servlet in the web.xml file, set a breakpoint in
your servlet using an IDE (JBuilder, Visual Cafe, etc.), and invoke the
servlet from a browser (execution should stop at your breakpoint). Thanks
for the tip, Jim!

Dustin Callaway
(callaway@sourcestream.com)



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message