19
8/22/2019 sun studio Debugging http://slidepdf.com/reader/full/sun-studio-debugging 1/19 Using the Debugger  January 2006 [Revision number: V2-3] Copyright 2006 Sun Microsystems, Inc.  This tutorial explains how to use the debugger in the Sun Java Studio Creator integrated development environment (the IDE).  Contents  - Setting Up an Example Application - Testing Your Application - Examining Local Variables - Programming for Maintainability - Watch Points - Validating Input - Viewing the Server Log - Setting an Exception Breakpoint - Making the Fix - About the Call Stack - Stepping Through Your Code - Using the HTTP Monitor - Editing HTTP Requests - Saving HTTP Requests  The Sun Java Studio Creator IDE has a built-in debugger to help you troubleshoot your programs. This tutorial illustrates some of the debugger's most used capabilities.  The online help has comprehensive documentation of the debugger. You can see the debugger help by choosing Help > Help Contents, and then in the Contents pane, open the Debugging Applications folder. Alternatively, to open the online help directly in a debugger topic, you can open any Debugger window and press F1 to see a help topic. For example, in Step 3 of Examining Local Variables, after opening the Local Variables pane, press F1 to see a topic describing that debugger pane.  Setting Up an Example Application  The example application is a simple Fahrenheit to Celsius temperature converter. 1. From the Java Studio Creator Welcome page, click Create New Project. In the New Project wizard, select: Categories: Web Projects: JSF Web Application 2. Click Next. 3. For Project Name, enter DebugExample. You can either use the default project folder, or specify a different storage location. 4. Click Finish. The project opens in the Visual Designer, with Page1 displayed. Next, drop some components on the page and implement an action handler. 1. From the Basic section of the Components Palette, and drag the following components onto the Visual Designer for Page1: r Text Field r Label (for Text Field) r Message (for Text Field) r Static Text r Label (for Static Text) r Button Arrange the components as shown in the following figure. 1

sun studio Debugging

Embed Size (px)

Citation preview

Page 1: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 1/19

Using the Debugger

 January 2006  [Revision number: V2-3]Copyright 2006 Sun Microsystems, Inc.

 

This tutorial explains how to use the debugger in the Sun Java Studio Creator integrated development environment (the IDE). Contents

 - Setting Up an Example Application

- Testing Your Application

- Examining Local Variables

- Programming for Maintainability

- Watch Points

- Validating Input

- Viewing the Server Log

- Setting an Exception Breakpoint

- Making the Fix

- About the Call Stack

- Stepping Through Your Code

- Using the HTTP Monitor- Editing HTTP Requests

- Saving HTTP Requests The Sun Java Studio Creator IDE has a built-in debugger to help you troubleshoot your programs. This tutorial illustrates some of thedebugger's most used capabilities. The online help has comprehensive documentation of the debugger. You can see the debugger help by choosing Help > Help Contents, andthen in the Contents pane, open the Debugging Applications folder. Alternatively, to open the online help directly in a debugger topic, youcan open any Debugger window and press F1 to see a help topic. For example, in Step 3 of Examining Local Variables, after opening theLocal Variables pane, press F1 to see a topic describing that debugger pane. 

Setting Up an Example Application

 

The example application is a simple Fahrenheit to Celsius temperature converter.

1. From the Java Studio Creator Welcome page, click Create New Project. In the New Project wizard, select:

Categories: Web Projects: JSF Web Application 

2. Click Next.

3. For Project Name, enter DebugExample. You can either use the default project folder, or specify a different storage location.

4. Click Finish. The project opens in the Visual Designer, with Page1 displayed.

Next, drop some components on the page and implement an action handler.

1. From the Basic section of the Components Palette, and drag the following components onto the Visual Designer for Page1:

r  Text Fieldr  Label (for Text Field)r  Message (for Text Field)r  Static Textr  Label (for Static Text)r  Button

Arrange the components as shown in the following figure.

1

Page 2: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 2/19

 

Figure 1: Page1 Layout 

2. Click the first Label component and change its text to Enter Degrees F: and then press Enter.

In the Properties window, the component's text property stores the new text.

3. Click the second Label component and change its text to Degrees C:.

4. Hold down Ctrl-Shift and click-drag from the Message component to the Text Field component.

The text displayed for the Message component changes to show that it is now associated with the Text Field. The Text Field uses theMessage component to display info() and error() messages.

5. Select the Button component. Click again to edit the button text and change it to Convert.

The Visual Designer should now look like the following figure.

Figure 2: Page 1 Final Layout 

Providing a Button Action Method

 At this point, the application does nothing. You will now provide an action method for the button to give yourself something to debug.

1. In the Visual Designer, double-click the Convert button. The Java Editor opens with the insertion point in the button1_action() method.

2. Insert the code in Code Sample 1 into the button1_action() method. This code reads a Fahrenheit value from the Text Fieldcomponent, calculates a Celsius value, and displays it in the Static Text component.

NOTE: If you notice a mistake in the code, please leave it in. It is there for the purposes of the tutorial.

2

Page 3: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 3/19

public String button1_action() {

  // Conversion is: tc = ( tf - freezeF ) / divisor

// get input string from Text Field 

String tfString = ((String)getTextField1().getValue());

Double tfDouble = new Double(tfString);

// extract the value and assign it to primitive doubledouble tf = tfDouble.doubleValue();

// calculate temperature in Celsius

double tc = tf - 32.0 / 1.8;

// convert double to String

String tcString = Double.toString(tc);

// print Celsius value

getStaticText1().setValue(tcString);

return null;

}

 3. Press Ctrl-Shift-F to reformat the code.

Your button1_action() method should now look like the following figure.

Figure 3: Button Action Method 

Testing Your Application

 Try some simple tests with your application:

1. Click the Run Main Project toolbar button or press Ctrl-F5 to build, deploy, and open the application in your web browser.

2. When the application starts, enter a number in the text field and click the Convert button. You should see converted values in the StaticText field.

3. Try entering real numbers and negative numbers as well as positive integers.

4. Enter 32, the Fahrenheit value for the freezing point of water. When you click Convert, you will see the Celsius value 14.2. This valueshould be 0.0. Even though the user interface seems to be working correctly, there is a problem in the program.

Code Sample 1: Button Action Method

3

Page 4: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 4/19

 

Figure 4: Program Output 

You might have already spotted the source of error, but you will use the debugger to find it. Because the error appears to be in yourconversion formula, you will set breakpoints in your button action method and examine the value of local variables during execution.

Examining Local Variables

 You will now examine the local variables in the button1_action() method.

1. Set a breakpoint in the code by clicking in the left margin of the return null; statement. Alternatively, with the edit cursor in theline of code, you can either press F9 or right-click and choose Toggle Breakpoint to set and unset a breakpoint.

Your Java Editor window should look like the following figure:

Figure 5: Setting a Breakpoint When you set a breakpoint in the debugger, execution pauses just before the breakpoint. Because the breakpoint has been set after theevaluation of the local variables in the button1_action() method, you are able to see their values in the Local Variablesdebugger window.

2. Begin a debugging session by choosing Run > Debug Main Project from the menu bar, or by pressing F5.

The IDE attaches the debugger to the project, rebuilds, and redeploys the application.

4

Page 5: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 5/19

 3. When the application opens in the web browser, enter 32 and click the Convert button.

Program control returns to the debugger in the IDE, and the values of local variables are shown in the debugger window's LocalVariables tab.

Figure 6: Viewing Local Variables When the program is paused, the breakpoint turns green.

The local variable values show no surprises: tfString holds the value of the string from the input text field, and tfDouble and tf hold the value of the converted Double object and double primitive, respectively. The only problem is that the calculated Celsius valuein tc and the string displayed are incorrect.

When you examine the calculation of the tc value, you notice that 32.0 is being divided by 1.8, and that value is being subtractedfrom tf. If you put parentheses around tf - 32.0, the conversion formula will work properly.

4. Choose Run > Continue from the menu bar, or press Alt-F5 to continue execution.

5. Change the calculation for the tc variable to read as follows:

double tc = (tf - 32.0) / 1.8;

6. Choose Run > Finish Debugger Session to end the debugger session.

7. Choose Run > Debug Main Project start a new debugger session.

NOTE: You might have to close the web browser and choose Run > Debug Main Project again to get the application to deploy.

8. When the web application is redeployed, again enter 32 and click Convert.

Control returns to the IDE, and the value of the local variable tc should now be the expected value of 0.0.

9. Press Alt-F5 to continue execution.

10. Enter 212 in the web browser and click Convert. Confirm that the value of tc is the expected value of 100.0. Press Alt-F5 to continueexecution, and the converted value 100.0 should appear in the web application.

 Variable Evaluation in Tool Tips 

When a debugging session is active, you can evaluate a variable directly in the Java Editor by hovering over the variable. If the variable isactive in the current context, its value is displayed in a tool tip.

For example, with the DebugExample application running in the web browser in debug mode as described above, enter 32 in the text field andclick Convert. When you return to the IDE and hover the mouse over the tc variable, you see the tooltip shown in Figure 7.

Figure 7: Evaluating a Variable In cases where a program includes different variables with the same name, the Java Editor displays the value based on the current context.

5

Page 6: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 6/19

 You can examine local variables only if you have local variables to examine. For example, suppose that the heart of the button1_action() method could have been condensed into the following single expression statement:

Code Sample 2: Condensed Button Action Method

public String button1_action() {

getStaticText1().setValue(Double.toString((((new

Double((String)getTextField1().getValue())).doubleValue( )-32.0) /

1.8)));

return null;

}

 When expressed this way, the method has no local variables, and the Local Variables window will reveal nothing about the workings of theprogram. This kind of condensation is undesirable because it makes troubleshooting and maintainability difficult. Another technique is to put Java assertions into your programs. The assert keyword evaluates a boolean expression and, if it is false, letsyou take action such as printing out an error message. Assertions let you easily test preconditions required by your program.

Watch Points

 You can monitor the value of an expression by setting a watch point. For example:

1. Make sure that a breakpoint has been set near the end of the button1_action() method — in the return null; statement, forexample.

2. In the Java Editor for Page1.java, select the following expression in thebutton1_action() method:

(tf - 32.0) / 1.8

3. Right-click and choose New Watch (Ctrl-Shift-W) from the context menu.

Figure 8: Setting a Watchpoint 

4. A dialog box appears in which you can edit the watch point expression. In this example, you will not edit the expression. Click OK inthe dialog box.

5. In the web browser, enter the Fahrenheit value 212. When the program pauses at the breakpoint, view the watch point in the Watchestab of the debugger window. The watch point reports on the current value of the expression. Do not continue execution yet.

Figure 9: Watching an Expression 

Programming for Maintainability

6

Page 7: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 7/19

6. Click the Value field in the Watches window and try to change the value from 100.0 to 50.0. If you type the new value and pressEnter, a message displays saying that you cannot set the value of an expression.

However, if you had set a watch point on a variable instead of an expression, you would have been able to change its value while theprogram was paused, just as you can from the Variables window.

7. In the Java Editor, select only the variable tc from the same line of code:

double tc = (tf - 32.0)/1.8 

8. Right-click and choose New Watch from the contextual menu.

A second watch point appears in the Watches window, and the value of the variable is shown immediately.

9. Click the ellipsis button (..) to the right of the Value field for tc and change the value to 50, and then click OK.

This time the IDE allows you to change the value.

Figure 10: Changing the Value of a Variable In the Watches window, the value 50.0 is assigned to the variable tc even though the calculation that determines it evaluates to 100.0.

10. A watch point is a handy way to evaluate an expression while the program is paused. For example, set a watch point on the followingexpression in the button1_action() method:

Double.toString(tc)

Verify that its value is "50.0".

11. Press Alt-F5 to continue program execution. As the request lifecycle completes, the watchpoint values are replaced by the message>Thread has been resumed<.

Validating Input

 So far, you have tested the application only with numbers. What happens if you enter a non-numeric character in the text field? As you mightguess, the consequences will be unpleasant. To find out just how unpleasant, enter the character a in the text field and click Convert. The webbrowser notifies you of an unhandled exception.

7

Page 8: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 8/19

 

Figure 11: Unhandled Exception in Browser Window 

Your application must test the input characters to make sure they are numeric. The IDE provides validators for just such uses.

You will now associate a Validator component with the input text field.

1. Choose Run > Finish Debugger Session (Shift-F5).

2. If necessary, click Design to open the Visual Designer.

3. In the Palette's Components tab, select and drag the Double Range Validator from the Validators category onto the Text Fieldcomponent in the Visual Designer, as shown in the following figure.

Figure 12: Setting a Validator on the Text Field 

4. Click the Run Main Project toolbar button or press Ctrl-F5.

NOTE: If the application does not deploy, close the web browser window in which the application was previously running, and thenrun the main project again.

5. When the application opens in your web browser, enter the character a and click Convert. The validator handles the exception bypassing a message to the Message component that you associated with the input text field. The Message component displays themessage to the user, as shown in the following figure.

8

Page 9: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 9/19

 

Figure 13: Validation Error Message 

You need to check one more thing: what happens if you enter an empty string. Click Convert without entering anything in the text field, andonce again you see an exception in the web browser. Clearly, the validator component hasn't solved all your problems.

Viewing the Server Log

 

Because the empty string error results in a JavaServer Faces exception, you can find more information in the server log created by the IDE. Tosee the log, go to the Servers window, right-click Deployment Server, and choose View Server Log.

Figure 14: Viewing Server Log 

The log file appears in the output window of the IDE. The most recent messages are appended to the end of the file. Lines like the followingtell the story of a Java language exception due to an empty string from the button1_action() method.

Caused by: java.lang.NullPointerException

at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)

at java.lang.Double.valueOf(Double.java:447)

at java.lang.Double.<init>(Double.java:539)

at debugexample.Page1.button1_action(Page1.java:289)

 

More about Log Files

 On Windows systems, the log files are in the following folder:

installation- directory\SunAppServer8\domains\creator\logs\

On Windows systems, installation-directory is typically the following path: 

C:\Program Files\Sun\Creator2\

 To produce log files, you can use either the system println() method or a log() method furnished with the IDE. The log() methodcan only be used with the IDE's preconfigured bean files, which are extensions to the FacesBean class. The println() method can beused in any Java file and might be more useful if you are importing external Java code.

9

Page 10: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 10/19

 Here is an example of printing the value of the tfString variable with each method. The logging statements are inserted in thebutton1_action() method following the line where tfString is declared, as follows:

Code Sample 3: Logging Statements

// Existing line

String tfString = ((String)getTextField1().getValue());

// Logging Statementslog("tfString logged = " + tfString);

System.out.println("tfString printed = " + tfString);

 If you build and run the application, and then convert the Fahrenheit value 32, you see messages like the following in the server.log file:

[#|2006-01-15T13:25:04.759-0600|INFO|

sun-appserver-pe8.1_02|javax.enterprise.system.container.web|

_ThreadID=21;|WebModule[/DebugExample]tfString logged = 32|#]

[#|2006-01-15T13:25:04.759-0600|INFO|

sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|

_ThreadID=21;| tfString printed = 32|#]

 The first line is created by the log() method, the second by the println() method. The server log information has the following format:

[#<Date-Time Identifier> | <Severity Level> |

<Server Identifier> | <Package Identifier> |

<Thread Identifier> | <Logged Information> | #]

 

Setting an Exception Breakpoint

 The browser exception message and the log entries give you enough information to know that there is something wrong with the application'sability to handle empty strings in the text field. By setting an exception breakpoint, you can learn more from the IDE debugger.

1. In the IDE, press F5 to start a debugger session.

2. Choose View > Debugging > Breakpoints to view the Breakpoints window.

3. Right-click in the Breakpoints window and choose New Breakpoint from the contextual menu. The New Breakpoint dialog box opens.

The following Caused by: line from the original web browser exception message tells you where to look for the error:

Caused by: java.lang.NullPointerException 

4. In the New Breakpoint dialog box, enter the following information:

Breakpoint Type: Exception Package Name: java.lang Exception Class Name: NullPointerException Stop On: Caught or Uncaught

Your dialog box should look like the following figure:

10

Page 11: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 11/19

 

Figure 15: Setting an Exception Breakpoint

 5. Click OK. The new breakpoint appears in the Breakpoints window.

6. In the web browser, make sure the text field is empty and click Convert. The IDE will pause execution when it encounters theexception.

Figure 16: Execution Paused at Exception Breakpoint 

If source code for the class in which the exception occurred is available, the source file will be displayed and the line where theexception occurred will be highlighted. In this case, source is not available, so the Java Editor highlights the line that led to theexception in Page1.java. The highlighted line attempts to convert the input string to a Double object.

This information confirms everything you already know and implies that you must somehow test the input to make sure it is not empty.

7. Press Shift-F5 to end the debugging session. You will now correct the error.

11

Page 12: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 12/19

 You could write a piece of code to test the input string to ensure that it is not empty. However, the IDE provides an easy way to validate thepresence of an input string: setting a property on the Text Field component.

1. In the toolbar above the Java Editor, click Design to display the Visual Designer.

2. Select the Text Field component.

3. In the Properties window for the Text Field component, select therequired property's checkbox.

Figure 17: Setting Required Property 

4. Deploy and run the program by pressing Ctrl-F5.

5. When the application opens in your web browser, click Convert without entering anything in the text field. You see an error messageinstead of the former exception.

6. Enter other values, including text strings, to make sure that the application gracefully handles all entries in the text field. Note that youcan convert values in scientific notation, such as -123.4e6. Note also that the Text Field ignores leading and trailing spaces becausethe Behavior > trim property is set by default (see Figure 17).

 

About the Call Stack

 The debugger gives you call stack control over program execution. The call stack, sometimes called a call chain, is a list that shows the orderof method calls that have been invoked but have not yet returned. The list shows the current method call at the top and parent calls insequence below.

When the program is paused, you can examine the call stack, make a call current, and pop a call from the stack (change the program executionso that the next statement to be executed is one of the calls made earlier on the stack). These options are available from the Run > Stack menu.

To see how the call stack works:

1. Make sure that a breakpoint is set at the return null; statement in the button1_action() method by clicking in the leftmargin, if necessary. The statement should appear as follows:

Figure 18: Breakpoint Set on a Line 

2. Press F5 to start a debugging session. The debugger will start, and the application will build and deploy.

3. When the web application opens in your browser, type 32 into the text field and click Convert.

Making the Fix

12

Page 13: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 13/19

 Focus will return to the IDE, and the breakpoint line will turn green to indicate that execution has paused and that the breakpoint is thecurrent line.

4. If the Call Stack window is not already displayed below the Java Editor window, choose View > Debugging > Call Stack to display it.The Call Stack window uses bold characters to identify the Page1.button1_action() method as the current call. If you scrolldown the call stack, you see a series of system calls, finally showing the original call to WorkerThread.run.

Figure 19: Viewing the Call Stack

 5. Below the Page1.button.action call, locate the first Method.invoke call. Double-click the call. The IDE shows the source

line if the source file is available.

Figure 20: Viewing Call Source The source file for the Method.invoke call is shown in Figure 20. Note that in this case the source file is marked read-only andcannot be edited.

6. Choose Run > Stack > Make Caller Current, and note that the previous call, SecurityUtil$1.run, becomes the current method inthe call stack.

13

Page 14: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 14/19

 

Figure 21: Making Caller Current 

You can also pop the topmost call, which removes the current method from the call stack and makes the previous call current. In general,popping a call from the call stack does not undo whatever effects the call might have caused. For example, if a call opens a databaseconnection and then you pop that call from the stack, the database connection remains open.

Note that exceptions thrown by Java Server Faces or validators won't be seen in the debugger's Call Stack output window because thoseexceptions interrupt the life cycle of the JavaServer Pages request. Similarly, you do not see values for local variables if the life cycle isinterrupted before the variables can be evaluated.

Stepping Through Your Code

 When the program is paused, you can step through lines of code. You will find the following commands on the Run menu:

Step Over (F10). Executes one source line. If the source line contains a call, executes the entire routine without stepping through theindividual instructions.

q  Step Into (F11). Executes one source line. If the source line contains a call, stops just before executing the first statement of theroutine. Program execution stops on the first line after the main routine, before any changes have been made to the state of the program.

q  Step Out (Shift-F11). Executes one source line. If the source line is part of a routine, executes the remaining lines of the routine andreturns control to the caller of the routine.

q  Run to Cursor (Ctrl-F10). Runs the current session to the cursor location in the Java Editor and pauses the program. You wouldtypically follow this command with one of the stepping commands. To stop program execution every time the program reaches theline, set a breakpoint.

To illustrate, start fresh by deleting all breakpoints and setting a new one:

1. Choose View > Debugging > Breakpoints to view the Breakpoints window.

2. Right-click and choose Delete All from the contextual menu.

14

Page 15: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 15/19

 

Figure 22: Deleting All Breakpoints 

3. In the Editor window, if necessary, click the Java button above Page1 to open the Java Editor, and then set a new breakpoint in byclicking in the left margin next to the following statement:

String tfString = ((String)getTextField1().getValue()); 

4. Choose View > Debugging > Local Variables to view the Local Variables window.

5. If you are in a debugging session, end it by pressing Shift-F5, and then choose Run > Debug Main Project to build and deploy the

program.NOTE: You can tell if you are in a debugging session by clicking the Run menu. If a debugging session is running, debugging choiceslike Finish Debugger Session are available.

6. In the web browser, enter a Fahrenheit value of 32 and click Convert. In the IDE, the breakpoint line will be highlighted in green toshow that it is the current line.

7. Press F10 to step over the code in the button handler. As you step through the code, the current line is highlighted in green. Note howlocal variables are evaluated one by one in the Local Variables window as each line executes.

Figure 23: Stepping Over Code While Viewing Local Variables 

8. Finish the debugger session by pressing Shift-F5.

15

Page 16: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 16/19

 

Using the HTTP Monitor

 The HTTP Monitor reveals the HTTP data flow between components of your application. You can use the HTTP Monitor either in adebugging session or with a normally deployed application resulting from running the main project.

The HTTP Monitor is implemented by means of the application server you are using. To ensure that the HTTP Monitor is enabled, check theApplication Server properties, as follows.

1. Choose View > Servers to make the Servers window visible.

2. Right-click Deployment Server and choose Properties from the contextual menu.

3. Enable the General > HTTP Monitor property if necessary, as shown in Figure 24, and close the dialog box.

Figure 24: Enabling the HTML Monitor 

In the following steps, you will see how the HTTP Monitor works.

1. Build and deploy the application by clicking the Run Main Project toolbar button or pressing Ctrl-F5.

2. After the application has deployed, click the HTTP Monitor tab in the IDE and expand the Current Records node in the left panel.

The left panel shows all HTTP request records for the client side of your application. Entries in Current Records are a history of thecurrent IDE session and is available until you exit the IDE. The Current Records history persists across restarts of the server but is lostwhen you exit the IDE. The records in the Saved Records node persist until you delete them.

3. Expand the GET DebugExample client-side record to reveal the Page1.jsp record. Nested nodes like Page1.jsp are the resultof an internal dispatch on the server. These forwarded or included requests are nested under the node that corresponds to the mainrequest. Note that not all servers provide this functionality.

4. Select Page1.jsp in the left panel and view the information in the right panel.

16

Page 17: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 17/19

 

Figure 25: The HTML Monitor 

The right panel shows session data for the selected request. The data includes cookie name/value pairs, session data, and servlet context. Youcan also view HTTP header data and client-server information, such as client protocol and IP address, and the server platform and host name.

Editing HTTP Requests

 To edit an HTTP record and replay it, perform the following steps:

1. In the right panel of the HTTP Monitor window, click the Request tab.

2. In the application running in the web browser, enter 32 and click Convert.

3. In the HTTP Monitor window, expand the Current Records node and locate the POST subrecord. Select the POST record to view therequest information.

Note that the value 32 that you typed in the application now appears in the Parameters area as input form1:TextField1 for thePOST request.

Figure 26: The HTML Monitor POST Request 4. In the left panel of the HTTP Monitor right-click the POST Page1.jsp node and select Edit and Replay from the contextual menu.

The Edit and Replay dialog box opens.

In the Edit and Replay dialog box, you can change Query, Request, Cookie, Server, and HTTP Header information for the POSTrecord.

17

Page 18: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 18/19

 

Figure 27: The Edit and Replay Dialog Box 

5. On the Query tab, click the ellipsis (..) to the far right of the form1:textField1 line and change the value from 32 to 212.

6. Click Send HTTP Request. The application in the browser accepts the request and changes the entered value from 32 to 212.

Saving HTTP Requests

 To save the POST request so that it persists in the next IDE session, perform the following steps.

1. In the left panel of the HTTP Monitor window, select the POST request record.

2. Right-click the POST request record and choose Save from the contextual menu. The POST request record is saved under the SavedRecords node in the left panel of the HTTP monitor window.

3. When you want to delete a saved record, right-click it and choose Delete from the contextual menu.

Summary

 In this tutorial you have used many of the important features of the debugger, including setting breakpoints and watches, viewing localvariables, stepping through code, using log files, viewing the call stack, and using the HTTP Monitor.

See Also:

q  Getting Started with Sun Java Studio Creatorq  Using the Java Editor

 This page was last modified: January 25, 2006

Sun and Third-party Trademarked Terminology

The following Sun trademarked terms might be used in the Sun Java(tm) Studio Creator tutorials:

q  Sun Java Studio Creator integrated development environment (IDE)q  Sun Java System Application Server version number (Application Server)q  Java Platform, Standard Edition technology (Java SE(tm) platform)q  JavaServer(tm) Faces technologyq  JavaServer Pages(tm) technology (JSP(tm) technology)q  Sun Java System Web Server version number (Web Server)q  Java Database Connectivity software (JDBC software)q  Enterprise JavaBeans(tm) specification (EJB(tm) specification)

18

Page 19: sun studio Debugging

8/22/2019 sun studio Debugging

http://slidepdf.com/reader/full/sun-studio-debugging 19/19

q  Solaris(tm) Operating System software (Solaris OS software)

The following third-party trademarked terms might be used in the Sun Java Studio Creator tutorials:

q  UNIX(R) softwareq  SPARC(R) processor

Copyright © 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. Inparticular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/ patents and one or more additional patents or pending patent applications in the U.S. and in other countries.

U.S. Government Rights - Commercial software.

Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and itssupplements. Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and the Java Coffee Cup logo are trademarks orregistered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.This product is covered and controlled by U.S. ExportControl laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclearmaritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or toentities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists isstrictly prohibited.

Note: Sun is not responsible for the availability of third-party web sites mentioned in this document and does not endorse and is notresponsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not beresponsible or liable for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content,goods, or services available on or through any such sites or resources.

Copyright © 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, États-Unis. Tous droits réservés.

Sun Microsystems, Inc. détient les droits de propriété intellectuels relatifs à la technologie incorporée dans le produit qui est décrit dans cedocument. En particulier, et ce sans limitation, ces droits de propriété intellectuelle peuvent inclure un ou plus des brevets américains listés àl'adresse http://www.sun.com/patents et un ou les brevets supplémentaires ou les applications de brevet en attente aux États-Unis et dans lesautres pays. L'utilisation est soumise aux termes de la Licence. Sun, Sun Microsystems, le logo Sun, Java et le logo Java Coffee Cup sont desmarques de fabrique ou des marques déposées de Sun Microsystems, Inc. aux États-Unis et dans d'autres pays.Ce produit est soumis à lalégislation américaine en matière de contrôle des exportations et peut être soumis à la règlementation en vigueur dans d'autres pays dans ledomaine des exportations et importations. Les utilisations, ou utilisateurs finaux, pour des armes nucléaires,des missiles, des armesbiologiques et chimiques ou du nucléaire maritime, directement ou indirectement, sont strictement interdites. Les exportations ouréexportations vers les pays sous embargo américain, ou vers des entités figurant sur les listes d'exclusion d'exportation américaines, ycompris, mais de manière non exhaustive, la liste de personnes qui font objet d'un ordre de ne pas participer, d'une façon directe ou indirecte,aux exportations des produits ou des services qui sont régis par la législation américaine en matière de contrôle des exportations et la liste deressortissants spécifiquement désignés, sont rigoureusement interdites.

Sun Microsystems n'est pas responsable de la disponibilité de tiers emplacements d'enchaînement mentionnés dans ce document et n'approuvepas et n'est pas responsable ou iresponsable d'aucun contenu, de la publicité, de produits, ou d'autres matériaux dessus ou fournis par de telsemplacements ou ressources. Sun ne sera pas responsable ou iresponsable d'aucuns dommages ou perte causés ou allégués pour être causé parou en liaison avec l'utilisation de ce produit ou la confiance dans des tels contenu, marchandises, ou services disponibles sur ou par des telsemplacements ou ressources.