Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
|
Debugging servlets in the JBuilder IDE
Servlets are great, but developing servlets can be quit difficult.
Compiling, copying to the web server, activating servlet through a web page, look at what goes wrong, change source, compiling...
There must be easier way to do this, and there is!
To be able to debug a servlet in the JBuilder IDE, we must create a web server written in Java, and start this from the JBuilder IDE. Then we can activate the servlet through a web page and we are able to debug our servlet using the JBuilder debugger. The web server is already included with the JSDK (Java Servlet Development Kit): sun.servlet.http.HttpServer. This class is a simple Java web server capable of executing servlets.
Next we must write a Java application that will create an instance of HttpServer and start the web server. This application functions as a wrapper for the web server. The following code is all we need to write:
import sun.servlet.http.*; public class DebugServer { public static void main(String[] args) { HttpServer webserver = new HttpServer(); webserver.run(); } }When this application is executed a small web server will be started, which listens on port number 8080 to HTTP requests.
Add the source file with the previous code to a project. Then create a servlet and add this to the project. Let's create a simple servlet using the Servlet Wizard:
We could of course write the web server wrapper application everytime we develop servlets. But we can better save this application and add the source file to every project in which we want to debug servlets. Once we have added the source file of DebugServer we make it the default runnable file of our project.
Now when we execute the Debug command the web server will be started and awaiting requests from the web browser.