锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国内精品久久影院,亚洲一级影院,国产精品亚洲综合天堂夜夜 http://www.aygfsteel.com/aldreamlau/category/27258.htmlmezh-cnMon, 12 Nov 2007 17:37:00 GMTMon, 12 Nov 2007 17:37:00 GMT60鍦╡clipse璋冭瘯JSP鍜宩ava紼嬪簭http://www.aygfsteel.com/aldreamlau/articles/159969.htmlaldreamaldreamMon, 12 Nov 2007 06:53:00 GMThttp://www.aygfsteel.com/aldreamlau/articles/159969.htmlhttp://www.aygfsteel.com/aldreamlau/comments/159969.htmlhttp://www.aygfsteel.com/aldreamlau/articles/159969.html#Feedback0http://www.aygfsteel.com/aldreamlau/comments/commentRss/159969.htmlhttp://www.aygfsteel.com/aldreamlau/services/trackbacks/159969.html鍘熸枃鍑哄錛?a >http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf

This tutorial gives you an overview of how to use the debugging feature of eclipse to debug your web or Java projects.

General

Author:

Sascha Wolski

Sebastian Hennebrueder

http://www.laliluna.de/tutorial.html ? Tutorials for Struts, JSF, EJB, Hibernate, xdoclet, eclipse and more.

Datum:

January, 25 2005
Development Tools

Eclipse 3.x

MyEclipse plugin 3.8

(A cheap and quite powerful Extension to Eclipse to develop Web Applications and EJB (J2EE) Applications. I think that there is a test version availalable at MyEclipse.)


PDF Version des Tutorials

http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf

Introduction

The Eclipse Platform features a Java debugger that provides all standard debugging functionality, including the ability to perform step execution, setting of breakpoints and values, inspecting variables and values, and to suspend and resume threads. With the extension MyEclipse you are able to debug JSP and included files too.



The debug perspective

First we will explain the debug perspective. You can activate the perspective under Windows > Open Perspective > Other...




Alternatively, you can click on the debug icon of the perspective tool bar.




Debug view

The Debug view displays the stack trace for the suspended threads for each target you are debugging. Each entry is the variable state of a method right when it called the next method. The view allows you to manage the debugging of a program in the workbench.




Variables view

The view displays information about the variables in the selected class. You can get information about the variable like value, size and more from this view.




Breakpoints view

The view lists all breakpoints you have set in the workbench project. In this view, you can enable or disable breakpoints, remove them, or add a new ones. You can also double-click a breakpoint to display its location in the editor.

This view also lists Java exception breakpoints, which suspend execution at the point where the exception is thrown. You can add or remove exceptions.






Expressions view

You can inspect data from each class of a suspended thread, and other places in this view. It opens automatically when an item is added to the view.




Debug a web project

In the next steps I will explain how you can debug a project. I will refer to the project JSP + Servlet you can download on our site. http://www.laliluna.de/assets/tutorials/java-servlets-jsp-tutorial.zip

Open the class BookEdit.java and set a breakpoint in the method doGet(..) at line 72. You can set a breakpoint by double-click on the info bar on the left edge of the editor, or right click Toggle Breakpoint.




Set the second breakpoint in the bookEdit.jsp file on the HTML start tag at line 14.

Note: If you don't have installed MyEclipse, you can't set a breakpoint in jsp and included files.




To see all breakpoints you can use the Breakpoints view in the debug perspective.

Breakpoint Properties

You can apply some properties to each breakpoint, for example how many times a breakpoint can hit before it suspends the thread or on which condition it suspends the thread.

Select the breakpoint right mouse button and choose the option Breakpoint Properties.









Hit Count

The hit count sets a number of times the breakpoint can be executed before the thread suspends. Very helpful in a loop expression or if you want to know the value of a expression after some hits.

Enable Condition

There are two options to suspend a thread by using a condition.

  • if the enabled condition is true

  • if the enabled condition changes

If you want that the condition suspends the thread when it is true select the option condition is true on Suspend when.

Example:

action.equals("edit");



If you want that the condition suspends the thread when the value of the condition changes select the option value of the condition changes on Suspend when.





Suspend Policy

You can define if the breakpoint suspends only the thread or the complete virtual machine.

Deploy and Debug

Now we want to debug the project, so deploy it and call it in your web browser.
Choose Edit on the list of books.




After you clicked the Edit link, eclipse shows you the following confirm window. You can choose if you want to switch to the debug perspective. Yes, you want it ;- )




The first entry in the debug view represents the state of the method where the breakpoint was set. You can preview the state of a entry simply by clicking on it, also the file will be open where the method is placed.




You can see the values of all variables of the selected entry in the Variables view.




A marked line and an arrow at the breakpoint shows that the debugger is suspended on this line.




If you've decided that you missed an important place in the execution process, perhaps the breakpoint was in the wrong place, or maybe you accidentally stepped over some code you wanted to inspect earlier in the process. Eclipse has a feature called Drop to frame, that essentially lets you 'rewind' the execution to the beginning of any method in the stack. This is especially useful when you perform variable modification or code hot swapping.
Right click on the frame and choose the option
Drop to Frame.





Inspect expressions

To get informations about expression, you can inspect a expression. Right click on the marked expression, you want to inspect and choose Inspect or press Ctrl + Shift + I. A pop-up window appears that holds the informations about the expression.






Watch expressions

Watch is similar to inspect an expression. Watch means that the expression will be added to the Expressions view, where you can watch the informations about the expression. Add two expressions to the Expressions view.

Mark the expressions, right click and choose Watch.




Now the two expression are in the Expressions view.






Display expressions

If you want to display the type and the value of an expression, mark the expression and choose the Display option from the context menu (right mouse button) or press Ctrl + Shift + D.


Run to Line

If you set a breakpoint and somewhere under the breakpoint is a line you want to go, you can use the option Run to Line. The code between the breakpoint and the selected line will be executed. Select the line you want to go, press the right mouse button and choose the option Run to Line or use the key binding Ctrl + R.


Debugging JSP files (supported by MyEclipse)


Debugging a JSP file is the same like debugging a Java class, but the most features (Watch, Inspect, etc) are not implemented. The only way to get the values of variables is the Variables view.



That's it. You will only need to debug, when you make mistakes. Avoid them and forget the tutorial.




aldream 2007-11-12 14:53 鍙戣〃璇勮
]]>
涓涓狫unit渚嬪瓙(杞嚜caterpillar.onlyfun.net)http://www.aygfsteel.com/aldreamlau/articles/159653.htmlaldreamaldreamSat, 10 Nov 2007 16:55:00 GMThttp://www.aygfsteel.com/aldreamlau/articles/159653.htmlhttp://www.aygfsteel.com/aldreamlau/comments/159653.htmlhttp://www.aygfsteel.com/aldreamlau/articles/159653.html#Feedback0http://www.aygfsteel.com/aldreamlau/comments/commentRss/159653.htmlhttp://www.aygfsteel.com/aldreamlau/services/trackbacks/159653.html
鍦ㄦ脯瑭︿竴鍊嬪柈鍏冩柟娉曟檪錛屾湁鏅傛偍鏈冮渶瑕佺鄲瀹冧竴浜涚墿浠朵綔鐐洪亱琛屾檪鐨勮硣鏂欙紝渚嬪鎮ㄦ挵瀵笅闈㈤欏嬫脯瑭︽渚嬶細

MaxMinTest.java
 1 package onlyfun.caterpillar.test;
 2 
 3 import onlyfun.caterpillar.MaxMinTool;
 4 import junit.framework.TestCase;
 5  
 6 public class MaxMinTest extends TestCase {
 7     public void testMax() {
 8         int[] arr = {-5-4-3-2-1012345};
 9         assertEquals(5, MaxMinTool.getMax(arr));
10     }
11 
12     public void testMin() {
13         int[] arr = {-5-4-3-2-1012345};
14         assertEquals(-5, MaxMinTool.getMin(arr));
15     }
16     
17     public static void main(String[] args) {
18         junit.swingui.TestRunner.run(MaxMinTest.class);
19     }
20 }

鎮ㄥ皣璦▓鐨凪axMinTool鍖呮嫭闈滄厠鏂規硶getMax()鑸噂etMin()錛岀暥鎮ㄧ鄲瀹冧竴鍊嬫暣鏁擱櫍鍒楋紝瀹冨戝皣鍊嬪垾鍌沖洖闄e垪涓殑鏈澶у艱垏鏈灝忓鹼紝欏劧 鐨勶紝鎮ㄦ墍婧栧倷鐨勯櫍鍒楅噸瑜囧嚭鐝懼湪鍏╁嬪柈鍏冩脯瑭︿箣涓紝閲嶈鐨勭▼寮忕⒓鍦ㄨō璦堜腑鍙互娓涘皯灝卞剺閲忔笡灝戯紝鍦ㄩ欏叐鍊嬪柈鍏冩脯瑭︿腑錛屾暣鏁擱櫍鍒楃殑婧栧倷鏄柈鍏冩柟娉曟墍闇瑕佺殑璩囨簮錛? 鎴戝戠ū涔嬬偤fixture錛屼篃灝辨槸涓鍊嬫脯瑭︽檪鎵闇瑕佺殑璩囨簮闆嗗悎銆?br />
fixture蹇呴爤鑸囦笂涓嬫枃錛圕ontext錛夌劇闂滐紝涔熷氨鏄垏紼嬪紡鍩瘋鍓嶅緦鐒¢棞錛岄欐ǎ鎵嶇鍚堝柈鍏冩脯瑭︾殑鎰忔兜錛岀偤姝わ紝閫氬父灝囨墍闇鐨刦ixture鎾板鍦ㄥ柈鍏冩柟娉曚箣涓紝濡傛鍦ㄥ柈鍏冩脯瑭﹂枊濮嬫檪鍓靛緩fixture錛屼甫鏂肩祼鏉熷緦閵鋒瘈fixture銆?br />
鐒惰屽皪鏂奸噸瑜囧嚭鐝懼湪鍚勫嬪柈鍏冩脯瑭︿腑鐨刦ixture錛屾偍鍙互闆嗕腑鍔犱互綆$悊錛屾偍鍙互鍦ㄧ辜鎵縏estCase涔嬪緦錛岄噸鏂板畾緹?span style="font-weight: bold;">setUp()鑸?span style="font-weight: bold;">tearDown()鏂規硶錛屽皣鏁稿嬪柈鍏冩脯瑭︽墍闇瑕佺殑fixture鍦╯etUp()涓壍寤猴紝涓﹀湪tearDown()涓姺姣錛屼緥濡傦細

MaxMinTest.java
 1 package onlyfun.caterpillar.test;
 2 
 3 import onlyfun.caterpillar.MaxMinTool;
 4 import junit.framework.TestCase;
 5 
 6 public class MaxMinTest extends TestCase {
 7     private int[] arr;
 8 
 9     protected void setUp() throws Exception {
10         super.setUp();
11         arr = new int[]{-5-4-3-2-1012345};
12     }
13 
14     protected void tearDown() throws Exception {
15         super.tearDown();
16         arr = null;
17     }
18     
19     public void testMax() {
20         assertEquals(5, MaxMinTool.getMax(arr));
21     }
22 
23     public void testMin() {
24         assertEquals(-5, MaxMinTool.getMin(arr));
25     }
26     
27     public static void main(String[] args) {
28         junit.swingui.TestRunner.run(MaxMinTest.class);
29     }
30 }

setUp()鏂規硶鏈冨湪姣忎竴鍊嬪柈鍏冩脯瑭estXXX()鏂規硶闁嬪鍓嶈鍛煎彨錛屽洜鑰屾暣鏁擱櫍鍒楁渻琚緩绔嬶紝鑰宼earDown()鏈冨湪姣忎竴鍊嬪柈鍏冩脯瑭? testXXX()鏂規硶緄愭潫寰岃鍛煎彨錛屽洜鑰屾暣鏁擱櫍鍒楀弮鑰冨悕紼卞皣鏈冨弮鑰冭嚦null錛屽姝や竴渚嗭紝鎮ㄥ彲浠ュ皣fixture鐨勭鐞嗛泦涓湪 setUp()鑸噒earDown()鏂規硶涔嬪緦銆?br />
鏈寰屾寜鐓ф脯瑭︽渚嬬殑鍏у錛屾偍瀹屾垚MaxMinTool欏炲垾錛?

MaxMinTool.java
 1 package onlyfun.caterpillar;
 2 
 3 public class MaxMinTool {
 4     public static int getMax(int[] arr) {
 5         int max = Integer.MIN_VALUE;
 6         
 7         for(int i = 0; i < arr.length; i++) {
 8             if(arr[i] > max)
 9                 max = arr[i];
10         }
11         
12         return max;
13     }
14     
15     public static int getMin(int[] arr) {
16         int min = Integer.MAX_VALUE;
17         
18         for(int i = 0; i < arr.length; i++) {
19             if(arr[i] < min)
20                 min = arr[i];
21         }
22         
23         return min;
24     }
25 }

Swing浠嬮潰鐨凾estRunner鍦ㄦ脯瑭﹀け鏁楁檪鏈冮’紺虹磪鑹茬殑媯掑瓙錛岃屽湪娓│鎴愬姛寰屾渻欏ず綞犺壊鐨勬瀛愶紝鑰?"Keep the bar green to keep the code clean." 姝f槸JUnit鐨勫悕璦錛屼篃鏄脯瑭︾殑鏈緄傜洰鐨勩?br />

aldream 2007-11-11 00:55 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 榆树市| 遂川县| 阿巴嘎旗| 石门县| 山阴县| 临泽县| 民乐县| 钟祥市| 昭苏县| 台前县| 宁陕县| 德兴市| 胶南市| 邓州市| 广州市| 恩施市| 南漳县| 罗源县| 鄢陵县| 蛟河市| 靖安县| 阿拉善右旗| 彝良县| 万山特区| 成武县| 陈巴尔虎旗| 新干县| 临城县| 阳信县| 徐汇区| 沙河市| 会同县| 汾西县| 治县。| 莫力| 额济纳旗| 邢台县| 兖州市| 朝阳市| 方正县| 团风县|