Sun Microsystems Logo

 

 
 

Sun[tm] ONE Studio 4, Enterprise Edition for Java[tm] with Application Server 7 Tutorial
Debugging the Application
PREV PREV NEXT

 

This section introduces you the ease by which you can debug class files and JavaServer Pages[tm] (JSP[tm]) source files using the IDE and the application server. To start debugging with the application server there is no set up required outside the IDE. All underlying debugging configuration is established automatically by the IDE and the application server.

  1. Prepare Web Module for Debugging
  2. Start the Debugger
  3. Debug the EJB[tm]
  4. Debug a JSP
  5. Stop the Debugger

1. Prepare Web Module for Debugging

Verify that several web module settings are defined for debugging JSP files. Also set the context root value in the web module.

1. In Explorer, navigate to the mysimple/src/jdbcSimpleWeb filesystem.

2. Select the web module's web.xml node and display its property sheet.

3. Select Sun ONE AS tab.

4. Select the JSP Param field and then click the ellipsis (...) button.

5. Verify that classdebuginfo and mappedfile properties are set to true.

6. Click OK to close the property editor.

7. Select the web module's WEB-INF node in the mysimple/src/jdbcSimpleWeb filesystem and display its property sheet.

8. Enter /my-jdbc-simple in the Context Root field.

This value matches the servlet context root value that you assigned while defining the web application.

2. Start the Debugger

To start the debugger:

1. Choose the jdbcSimpleApp J2EE application node.

2. In the IDE's main menu bar, choose Debug -> Start.

The server1 instance of the application server restarts, and the IDE switches to the debugging workspace. In addition, the index.html page is displayed in the web browser. Note that the application is redpeloyed before the debugging session begins.

Browser does not come up? Depending on the browser in use, you might have to access the web application through your browser directly.


3. Debug the EJB

1. Open GreeterDBBean.java file in the source editor.

2. Move the cursor to the following line:

if(currentHour < 12) {

3. Right-click and select Debug -> Toggle Breakpoint.

The line in the source editor changes its background color indicating that a breakpoint has been set.

4. In the web browser, type a name, for example TESTER, and click Process.

Execution of GreeterDBBean.java stops at the breakpoint, and the line is highlighted in another color.

5. In the IDE's main menu bar, select the Debug tab.

In the Call Stack view, expand the samples.jdbc.simple.ejb.GreeterDBBean.getGreeting node.

Under the node, you can see the variables declared in the getGreeting method. One of the variables is named currentHour and it stores the current hour.

6. In the IDE's main menu bar, choose Debug -> Step Over a few times until the execution reaches the System.out.println statement.

The value of the message variable changes from null to "morning," "afternoon," or "evening" depending on the value of currentHour variable.

7. Select the message variable and display its properties.

If the properties sheet is not visible, click Properties () button in the Debug window.

8. Type "day" (including the quotes) in the Value field.

9. Select Debug -> Continue.

The debugger continues execution, and the web browser greets "Good day, TESTER."

10. Move the cursor to the line with the breakpoint and select Debug -> Toggle Breakpoint.

The breakpoint is removed from the line, and its background color resets to the normal editing color.

4. Debug a JSP

To debug GreeterDBView.jsp:

1. Open GreeterDBView.jsp in the source editor.

2. Move the cursor to the following line:

Good <%= messageString%>, <%= nameString%>.

3. Right-click inside the source editor and choose Compile.

You must compile the JSP in the IDE to allow the IDE to correlate between the JSP source file statements and the underlying servlet class file which implements the JSP file.

4. Right-click and select Debug -> Toggle Breakpoint.

The line in the source editor changes its background color indicating that breakpoint has been set.

5. In the web browser, type a name, for example TESTER, and click Process.

Execution of the GreeterDBView.jsp page stops at the breakpoint, and the line is highlighted indicating that execution stopped at the line.

6. In the Call Stack view, expand the _jasper._GreeterDBViwe_jsp._jspService node.

Under the node, you can see the variables for GreeterDBView.jsp.

7. Select nameString variable.

Next to the nameString variable, the "TESTER" string is shown because the name, entered in Step 5, is stored in the nameString variable.

8. Type "HUMAN" (including the quotes) in the Value field.

The value of nameString variable changes to "HUMAN".

9. In the IDE's main menu bar, select Debug -> Continue.

The debugger now continues execution of GreeterDBView.jsp, and the web browser shows HUMAN in the greeting instead of TESTER.

10. Move the cursor to the line with the breakpoint and select Debug -> Toggle Breakpoint.

The breakpoint is removed from the line, and its background color resets to the normal editing color.

5. Stop the Debugger

To stop the debugger:

1. In the IDE's main menu bar, select Debug -> Finish.

The Finish Debugging Session dialog box appears.

2. Make sure that all running sessions are checked.

3. Click OK.

Once you have completed these exercises, proceed to the final section, Summary.

PREV PREV NEXT