Use a simple web application to describe the Web server configuration, application deployment, and Debugging Processes Using myeclipse.
I. Prepare development tools
Eclipse 3.1.2 and myeclipse4.1.1 are used here. Of course, Java is usually used to develop network applications, so Web servers are indispensable. atat5.0 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. It doesn't matter if you use j2sdk 1.5.0 _ 06-b05 here, we can use all the functions.
:
Http://www.inspiresky.com/bbs/dispbbs.asp? Boardid = 13 & id = 6356 & page = 1
Http://www.inspiresky.com/bbs/dispbbs.asp? Boardid = 13 & id = 3889 & page = 1
Http://java.sun.com
Http://www.eclipse.org
Http://www.apache.org
Http://www.myeclipseide.com/ContentExpress-display-ceid-10.html
The myeclipse registration code is provided here for personal study and research purposes only. Company users should purchase their own serial numbers.
Ii. Software Installation and Registration
First, install JDK. Here I will use the default installation, and the directory will not change. C:/program files/Java. There are two folders, one for JDK and the other for path, please go to the Internet to find the relevant information. I have mentioned many articles.
For tomcat installation, we use the installation file of the EXE version. Except for the Directory selected, all the other files are installed by default. Here we install them in D:/tomcat5.5, note that it is troublesome to have spaces in the middle.
Eclipse is easy to install. Just unpack it and place the unwrapped file eclipse folder to the appropriate installation directory, for example, D:/eclipse. In the cmd.exe file, start eclipse, set the JDK and working path, and you will be able to see the welcome page of Eclipse. Here we do not use eclipse, so close myeclipse as an EXE installation file, there is an installation wizard, directly double-click the installation, select the eclipse Installation Directory D: /eclipse and its own installation directory. Here we use PSE, and next. 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 interface for integrating e. Enter the registration code of myeclipse, open the menu window-> preferences, and open myeclipse-> subferences in the menu tree of the dialog box, N... 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 WEB Project
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, and enter webtest in the projects Name of project details. The default value is used for other projects, note that the context root URL here is/webtest. Otherwise, you must use it in IE. 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 convenient to use myeclipse.
4. Create a "hello" class and 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 Kage Explorer ), right-click a package and choose new> package to create a new package. specified resky. bean. Select the new package, right-click the New-> class, and enter the static void main option in name. All others are default. Click Finish to create the class.
The Edit class code is as follows:
Package com. Alibaba resky. Bean;
/** Junsan *Http://www.inspiresky.com/bbs*/
Public class hello
{Private string message = "Hello World ";
/*** @ Return returns the message .*/
Public String getmessage ()
{Return message ;}
/*** @ Param message the message to set .*/
Public void setmessage (string message)
{This. Message = message ;}}
Note that the bean attribute operation method can define the attribute first. Then, in the editing window, right-click the menu source-> Generate getters and setters, and select the property of the get and set methods to be generated.
5. Create a JSP page
In the webtest project, select the webroot folder, right-click the menu New-> JSP, and change file name to index. jsp. By default, click Finish and press
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 "-// W3C // 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>
Note that the red part is the code we added. Well, our code has been compiled.
6. Configure the Tomcat server
Eclipse menu, window-> preference... In the preference dialog box, locate "myeclipse-> application servers-> tomcatat" in the menu tree, select "enable" in the dialog box, and click "Browse" in the Tomcat home directory input box, select the tomcat installation root object omcat5.5. the other boxes are automatically filled. Click Apply. Select JDK in Tomcat 5. Note that the default runtime environment is JRE. Set JDK here. Otherwise, myeclipse will not work properly.
The Tomcat server cannot run normally.
Click the Add button to write JDK 1.5.0 _ 06 to the JRE name, and select the JDK root directory in the Browse selection box. Here is C:/program files/Java/jdk1.5.0 _ 0 6, 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. Every time you click e, a problem occurs. If you do not click this button to go to another configuration page, the above configuration will be lost.
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 loaded in advance. Some packages are used only when the server is started to initialize the web application; the third is the class that is not packaged. We don't care about it here.
Now you can click the OK button in the preference dialog box to complete tomcat configuration. VII. Subordinate Web Applications
This is simple. Select the root directory of the webtest project, right-click the menu myeclipse-> add and remove projects deployments... Make sure projects is webtest. Click Add. In the displayed dialog box, select Tomcat 5 as the server. The following two single options are exploaded archive and directory-based and package-based, this is done by myeclipse. We do not need to compress the war package by using the directory deployment method, and the rest will return to the previous page regardless of its button.
If the server is specified, deploy the Application below. Select the five items in the server list in the dialog box. The dimmed button becomes available. Remove is used to 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
In the eclipse graphic menu bar (the "Redeploy" button on the left and the "self-dropping" browser on the right), click the drop-down button, and then 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 enterHTTP: /localhost: 8080/webtesT/, we can see the following information:
Hello world!
This is my JSP page. It indicates that the operation is successful.
This article is from 51cto. com technical blog