I,Prepare development tools
Eclipse is used here 3.0.1 For the corresponding myeclipse, the web server uses Tomcat 5.5.05 (to set breakpoints in JSP for debugging, Tomcat 5 is required. of course, j2sdk is also required. Here we use j2sdk 1.5.0 _ 05. It doesn't matter if it is JDK 1.5.0 or above.
Ii. Software Installation and Registration
Myeclipse is an EXE installation file. If you have an installation wizard, double-click the installation file and select the eclipse installation directory (such as D:/eclipse) and its own installation directory (such as D:/myeclipse ), next is all the way.
The installation of other software is not always done. The following creates a simple project to describe the application of myeclipse.
3. Create a WEB Project
Open the myeclipse development interface, file-> New-> projects ..., Open the Create Project dialog box, select myeclipse-> J2EE projects-> Web project, click Next, and enter webtest in the projects name of web project details. The default value is used for other items, note that the context root URL here is/webtest. Otherwise, you must enter the corresponding name in IE to use it. Check whether the tag library is supported at the bottom. Choose jstl1.1. Click Finish to create the project.
4. Create a hello class
Select the SRC folder under the project webtest (Note: If this folder cannot be found under package explorer, go to the eclipse User Guide, window-> show view-> package Explorer ), right-click a package and choose new> package to create a new package. specified resky. bean. Select the new package, right-click New> class, and enter hello in name to remove the public static void main option. All others are default. Click Finish to create the class.
EditCode, As shown below:
PackageCom. Alibaba resky. Bean;
PublicClassHello {
PrivateString message = "Hello World ";
/**
*@ ReturnReturns the message.
*/
PublicString getmessage (){
ReturnMessage;
}
/**
*@ ParamMessage the message to set.
*/
PublicVoidSetmessage (string message ){
This. Message = message;
}
}
Note that the bean attribute operation method can define the attributes first. Then, right-click the edit window and choose source> Generate getters and setters, in the dialog box, select the property of the get and set methods to be generated to confirm.
5. Create a JSP page
In the webtest project, select the webroot folder, right-click the menu New-> JSP, and change the file name to index. jsp. By default, click Finish to create the folder.
Edit the content of the JSP file as follows:
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
<JSP: usebean id = "hello" class = "com. Alibaba resky. Bean. Hello" Scope = "page"/>
<JSP: setproperty name = "hello" property = "message" value = "Hello world! "/>
<! Doctype HTML public "-// W 3c // Dtd html 4.01 transitional // en ">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> my JSP 'index. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>
<Body>
<JSP: getproperty name = "hello" property = "message"/> <br>
This is my JSP page. <br>
</Body>
</Html>
The red part is the code we added. OK. The Code has been compiled.
Vi. ConfigurationTomcatServer
Eclipse menu, window-> preference ..., Open the preference dialog box and find myeclipse-> application servers-> Tomcat 5 in the menu tree. Select five Tomcat items. In the dialog box, select the Enable single-choice button, click the Browse button in the Tomcat home directory input box, and select the installation root directory of Tomcat. Here is D: \ tomcat5.5, other boxes are automatically filled. Click Apply.
Select JDK in Tomcat 5. Note that the default runtime environment is JRE. Set it to JDK. Otherwise, myeclipse cannot be a web application, the Tomcat server cannot run normally. Click the Add button to write data to JDK in JRE name. 1.5.0 _ 05, and then select the JDK root directory in the Browse selection box. Here is D: \ jdk1.5.0 _ 05. For other default values, click OK. In Tomcat JDK name, select the one we just created, that is, jdk1.5.0 _ 05. Click the Apply button and click it every time. Sometimes there is a problem with eclipse. If you don't click this button, you will lose the above configuration when you go to another configuration page.
Make sure that the debug mode is selected in the launch of Tomcat 5.
Now you can click the OK button in the preference dialog box to complete tomcat configuration.
VII. SubordinatesWebApplicationProgram
This is simple. Select the root directory of the webtest project, right-click the menu myeclipse-> add and remove projects deployments ..., In the displayed dialog box, make sure that projects is webtest. Click Add. In the displayed dialog box, select Tomcat 5 as the server. The following two single options are displayed, exploaded archive and packaged archive are directory-based subordinates and package-based subordinates, which are all made by myeclipse. We use directory deployment instead of war packages. Click finished to return to the previous page.
OK. The program has been deployed. Run and debug the program below.
8. Run the debugging program
Find
(The one on the left of this button is the redeployment button, and the browser on the right is the built-in one). Click the drop-down button, select Tomcat 5, and click the Start menu to start Tomcat.
When the Consol window prompts that Tomcat is successfully started, we can run our program. Open an IE browser window and enter http: // localhost: 8080/webtest/. The following information is displayed:
Hello world!
This is my JSP page.
The operation is successful.
Next, let's talk about debugging. At this time, it's the same as normal debugging, with a breakpoint added. JSP files and class files can be debugged in one step.
Open the hello. Java edit box and add a breakpoint in the return message; line. Refresh the IE window, And the eclipse window will appear, stopping at the breakpoint. Press F8 to delete the breakpoint.
In the edit box of the index. jsp file, go to <JSP: getproperty name = "hello "... /> Place a breakpoint on a row and refresh the IE window. Then, go back to the eclipse editing window and check that the cursor has stopped at the breakpoint line.
Finally, you can debug it in JSP !!!
Special thanks to junsanArticle<Getting started with myeclipse development and debugging Web Application Instances> and enthusiastic help allow me to gain a lot in less time.