Myeclipse development and debugging JSP, Servlet, JavaBean, JSF, structs etc

Source: Internet
Author: User

A simple web application is used to describe the Web server configuration, application deployment, and Debugging Processes Using myeclipse.

I,Prepare development tools

Eclipse is used here 3.1.2 And myeclipse4.1.1. Of course, Java is usually used to develop network applications, so Web servers are indispensable. Tomcat 5.5.15 is used here. Of course, if you do not have j2sdk, then all the programs cannot be compiled and run. So, you should also prepare one. Here we use j2sdk 1.5.0 _ 06-b05. It doesn't matter if it is jdk1.5.0 or above, we can use all the functions.

:

Http://java.sun.com

 

Http://www.eclipse.org

Http://www.apache.org

Http://www.myeclipseide.com/ContentExpress-display-ceid-10.html

 

Ii. Software Installation and Registration

First, install JDK. Here I use the default installation, and the directory will not change. c: \ Program Files \ Java. There are two folders, one is JDK and the other is JRE. If you want to set a classless path, go to the Internet to find relevant materials. Many articles have been mentioned.

For tomcat installation, we use the installation file of the EXE version. Except for the Directory selected, all other files are installed by default. Here we install them to D: \ tomcat5.5. Note that the space in the middle is removed, it is troublesome to have spaces.

Eclipse is easy to install. Just unpack it and place the unwrapped file eclipse folder to the appropriate installation directory, for example, D:/eclipse. Find the eclipse.exe file in the installation directory, start eclipse, set the JDK and working path, and you will see the welcome page of Eclipse. Here we do not use eclipse, so disable it.

Myeclipse is an EXE installation file. If you have an installation wizard, double-click the installation and select the eclipse Installation Directory D:/eclipse and its own installation directory. Here, use D: \ myeclipse \ eclipse, next is all the way.

In the program group, we can find the myeclipse program group and click open. If you do not have a default working path, select a working path and you will see a typical eclipse interface integrated with myeclipse.

Enter the registration code of myeclipse, open the menu window-> preferences, open myeclipse-> subferences in the menu tree of the dialog box, click Enter subferences... Enter the user name and password.

OK. All the required software has been installed. Let's create a simple project to illustrate the application of myeclipse.

3. Create a webEngineering

Because only the basic operations and settings of myeclipse are described here, no complicated project is involved, and you can bypass the similar 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.
We can see that the classes required for the new project have been automatically loaded, and there is also a J2EE class environment variable, which is the convenience of using myeclipse.

4. Create a helloClass

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. test. 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.

The Edit class code is as follows:

PackageCom. Test. Hello

Public ClassHello {

PrivateString message = "Hello World ";

PublicString getmessage ()
{ReturnMessage ;}

Public VoidSetmessage (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. CreateJSPPage

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> <Title> my JSP 'index. jsp 'starting page </title>

<Body> <JSP: getproperty name = "hello" property = "message"/> <br> This Is My JSP page. <br> </body>

</Html>

Note that the red part is the code we added. Well, our 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 _ 06, and then select the JDK root directory in the Browse selection box. Here is c: \ Program Files \ Java \ jdk1.5.0 _ 06. For other default values, click OK. In Tomcat JDK name, select the one we just created, that is, jdk1.5.0 _ 06. 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.

In paths, there are some class path settings. The first is the class path that is loaded in advance. Some packages will be used when the server is started to initialize the web application; the second is used only during running; the third is the class without packaging, so we don't care about it here.

 

Now you can click the OK button in the preference dialog box to complete tomcat configuration.

VII. SubordinatesWebApplications

 

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.

If the server is specified, deploy the Application below. Select the five Tomcat items in the server list in the dialog box. The gray button becomes available, and the remove and redeploy buttons remove deployment and redeploy. Click redeploy, you can click this button to redeploy the modified project. Click here.

 

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 one on the right is the self-generated browser.) 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.

You don't need to talk about other debugging. You only need to use eclipse to check the attribute status value and the like. It is the same as debugging in time.

Now, we have explained the basic usage of myeclipse.

Source: http://blog.csdn.net/junnef/archive/2006/03/11/621992.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.