This article mainly introduces how to use Sysdeo Eclipse Tomcat Launcher Plugin to edit and debug JSP and servlet, it is best to refer to my previous article.
"Graphical use Eclipse3.0.1 Lomboz3.0.1 Tomcat5.0.28 Development JSP" series can deepen the understanding of the article.
I. need software
Sysdeo Eclipse Tomcat Launcher Plugin
Homepage
Http://www.sysdeo.com/eclipse/tomcatplugin.html
download
http://www.sysdeo.com/eclipse/tomcatpluginv3.zip
This is an Eclipse plugin that helps to edit the JSP file.
Install plugin, reference
"Installing the Eclipse plugin using the LINKS"
2. Environmental configuration
In order to edit and debug JSP files, environmental configuration is a bit trouble, there are several points to pay attention.
1. Check the settings of the environment variable.
Right click on "My Computer" -> Advanced -> Environment Variable,
Check if java_home, whether the Tomcat_Home variable points to its installed directory;
Does the PATH variable contain "% java_home% / bin;";
Does the ClassPath variable contains "% java_home / lib / Tools.jar;"
2. Point the Java running environment in Eclipse to JDK, not JRE.
In the Eclipe main window, "Window" -> Preferences -> Java-> Installed JRE
3. Configure the Sysdeo Tomcat plugin
Context explanation
The Context element represents a web application and runs on a particular virtual host. Each web application is based on a Web Application Archive (WAR) file, or a directory containing the content after the WAR file is decompressed.
Match the URI's maximum possible prefix with each context path, Catalina selects the corresponding web application to process HTTP requests. Once selected, according to the servlet map defined in the Web Application Deployment Descriptor file, Context selects a correct servlet to handle the request. The servlet mapping must be defined in /web-inf/web.xml in the web application directory hierarchy.
You can nest any of the context elements in a host element. The path to each context must be unique and defined by the Path property. In addition, you must define a context path length of 0, which is called the default web application of the virtual host to handle those requests that cannot match any Context path.
In addition to nesting the Context element in the Host element, you can also store them in a single file (in .xml as a suffix), place below the $ CATALINA_HOME / CONF / [Enginename] / [Hostname] / directory.
(Note: Catalina is Tomcat notior)
Switch to Advanced Options
Switch to JVM Setting options
Switch to Tomcat Manger App to add a user to the management interface.
Click "Apply" and "OK".
4. Add "Tomcat Project" to the New menu.
Window -> Custom Perspective -> Shortcut -> New -> Java
3. Write program
1. Create a Tomcat project.
Right-click on the "Pack Explorer" window, new creation -> Tomcat Project
Fill in the project name: TomcatSample, click "Finish".
2. Right-click "Tomcatsample", new-> file, fill in the file name: index.jsp3. Modify Index.jsp
Tomcatsample / index.jsp.jsp
<%
String s = "Welcome JavaMxj Blog!";
Out.println (s);
%>
4. Click "Run Tomcat" icon
5. If everything is normal, enter "http: // localhost: 8080 / tomcatsample / index.jsp" in the browser window.
IV. Debug JSP program
1. Right-click the Work directory under the Tomcatsample project, click "Refresh" in the pop-up menu. After clicking, you will find that there is a file in this directory, open the "index_jsp.java" file, in the right column "Out.println (s);" add a breakpoint.
2. Then refresh the browser window. At this point, Eclipse will pop up a window, ask if you switch to the "Debug" view, select "Yes".
3. In this view, find the variable S, right click, select "Changed value", enter "Sysdeo Tomcat Plugin!" In the pop-up window.
4. Click the "Continue" button.
5. At this time, the browser window has reflected the debugging changes.
V. Edit servlet
On the basis of successful editing and debugging JSP, it is relatively simple to edit and debug the servlet program.
1. Stop the Tomcat server first. Right click on the "Web-INF / SRC" directory, create new -> class,
Fill in the package name: "javamxj.tomcat.servlet"
Fill in the class name: "servletsample"
Click to complete.
2. Modify servletsample.java as follows:
Servletsample.java
/ *
* Create date 2004-10-18
* Author javamxj (9cbs blog)
* /
Package javamxj.tomcat.servlet;
Import java.io. *;
Import javax.servlet.http. *;
Import javax.servlet. *;
Public class servletsample extends httpservlet {
PRIVATE STRING S;
Public void doget (httpservletRequest Req, httpservletResponse res)
Throws ServleTexception, IOException
{
PrintWriter out = res. maxwriter ();
String s = "Hello, JavaMxj Blog!";
Out.println (s);
Out.close ();
}
}
3. Create a web.xml file in the web-inflicity, save the file.
WEB-INF / Web.xml
XMLns: XSI = "
http://www.w3.org/2001/xmlschema-instance "
XSI: SchemAlocation = "
http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd "
Version = "2.4">
4. Start the Tomcat server, enter "http:// localhost: 8080 / tomcatsample / servletsample" in the browser window
6. Debug the servlet program
1. Add a breakpoint to the servletsample.java file, as shown in the figure:
2. Refresh the browser window, switch to the "Debug" view of Eclipse, change as follows:
3. The browser window is as follows:
7. Discuss the mechanism
1. In the Tomcat Directory / Conf / Server.xml file, or there is a TomcatSample.xml file in Tomcat Directory / Catalina / LocalHost, which should be included in these two files:
(Note that the above statement will be different due to the different directories of Eclipse.)
2. Enter: "http: // localhost: 8080 /", click on the "Tomcat Manager" link on the left, one window will pop up, let you enter the username and password, in the second largest "environment configuration" In the third section of the medium, you have added a user to the Tomcat management interface, enter this user's username and password, here is "admin", "javamxj".
3. After entering the correct username and password, you will enter the Tomcat management interface, you can see that TomcatSample is running. You can stop, overload, or uninstall it.
4. Uninstall the Context definition from Eclipse now
Right-click Tomcatsample Directory -> Tomcat Project-> Remove Context Difinition, as shown below:
5. When you refresh the browser window of the Tomcat management interface, you will find that "/ tomcatsample" has disappeared. at the same time,
"
6. To re-add "/ tomcatsample" to the Tomcat application, you need to right-click the TomcatSample directory-> Tomcat Project-> Update Context Difinition, then restart Tomcat. So much, mainly for the next article, "How to use the Lomboz plug-in compile JSP" to make a paving, but also to better understand the use of this plugin.