Pr.Pg Next Pg

Debugging Servlet using Netbeans tutorials

  • It is possible to execute and debug servlets from within NetBeans. This is done by using the internal Tomcat server that comes with NetBeans.

  • When you execute a servlet in Netbeans, it always try to start the internal tomcat.

  • Since tomcat is running inside NetBeans, you will be able to set breakpoints in the code and stop execution of the servlet. You will still use the browser to interact with the servlet, but control will return to NetBeans when a breakpoint is encountered.

  • Below are the steps for servlet debugging in Netbeans:

    • Create a Servlet in source package.

    • Place a breakpoint on a line inside of doGet in the servlet by clicking in the left margin of the code window as below:

Servlet debugging in netbeans

    • Now from Debug menu click Debug file or press (Ctrl+Shift+F5).

    • Now Netbeans will start the internal Tomcat and control will pass to the breakpoint in Netbeans for examine the current line as below:

Servlets debuging in netbeans

    • Now in this state it is possible to execute statements individually. There are many options for controlling program execution. As below bar shows:

    Servlets Debugging tools in netbeans

  1. Finish Debugger : It Finishes or stop the debugging process.

  2. Pause: Pause the debugging process.

  3. Continue: Start executing again. Stop at next breakpoint.

  4. Step Over: If the current statement has a call to a subroutine, then execute the entire subroutine.

  5. Step Over Expression: It enables you to proceed through each method call in an expression and view the input parameters as well as resulting output values of each method call. You can invoke the Step Over Expression command just as you would any other step commands. 

  6. Step Into: If the current statement has a call to a subroutine, then move into the subroutine.

  7. Step Out: If the current statement is in a subroutine, then execute the remaining statements in the subroutine and return to the caller.

  8. Run to Cursor: Execute all the statements from the current program location to the line of code that contains the cursor.

  9. Apply Code Change: Apply Code Changes feature, which lets you debug code, make fixes, and then continue debugging without restarting the debugging application.

Pr.Pg border                                              Next Pg