Debugging a Servlet

An error occurred during the execution of your application and you want to analyze it.

Prerequisites

Debugging is activated – that is, the server process has been stopped and restarted in debugging mode.

Procedure

...

       1.      Open the source code of the servlet QuickReservationServlet.java: In the J2EE Explorer, double-click J2EE_QuickCarRentalWeb ® source ® com ® ... ® QuickReservationServlet.java

       2.      Display the source code and navigate to the beginning of the saveAction method.

       3.      In the saveAction method, right-click the left bar of the editor frame above the first Java statement to open the context menu and choose Add Breakpoint.

       4.      To start the J2EE application in the debugger, you require a launch configuration. Choose Run ® Debug... in the main menu.
In the list, select J2EE Application and choose New.

       5.      In the Name field, enter QuickCarRentalWeb.

Choose the Browse… button next to the field Enterprise Application Project, select the project J2EE_QuickCarRentalEar. Choose OK.

Choose the ReadioButton next to Servlet Click the Choose… button next to the field Servlet:, select the servlet QuickReservationServlet, and choose OK.

       6.      The configuration is now complete; you can start the debugger by choosing Debug.

       7.      The SAP NetWeaver Studio automatically switches to the debug perspective. The Web application is started in an external browser.

       8.      Enter valid date values in the input fields of the Web application and choose Add Reservation.

       9.      Change back to the SAP NetWeaver Developer Studio. The application was stopped at the breakpoint and can now be analyzed.

You have the following debugging options:

Key

Description

F5: Step Into

Jumps to the next statement

F6: Step Over

The next command is executed without jumping to the current statement<0} 

F7: Step Return

If you previously chose F5, you can choose F7 to cancel the debugging of the current command

   10.      Use the F6 key for executing all statements within the saveObjects method and observe the variable contents in the Variables window of the debug perspective.

   11.      The pickupLocation variable does not have a valid value (null) assigned to it.

The debugging mode enables you to dynamically change the variable contents.

   12.      Double-click the pickupLocation variable in the Variables window of the debug perspective.

   13.      Enter a location in the displayed input field and proceed with debugging. The application will no longer generate error messages.

Terminating Debugging

Exit debugging to correct the wrong assignment in the source code.

If you want to exit debugging, you must terminate the threads in the IDE (debug perspective).

...

       1.      In the Debug window, select the top node (QuickCarRental[J2EE Application]).

       2.      Right-click and choose Terminate from the context menu.

       3.      Then choose Remove All Terminated from the context menu.

Correct the source code of the servlet. Use the procedure described in Preparations for Debugging a Servlet to restore the original status.