Reprint, author: Xu Rongsheng.
Download a Tomcat plugin, you can easily call the external independent installation Apache Tomcat for JSP, servlet debugging. Still sneak peek, come see Eclipse plus Tomcat to track debug servlets how simple!
We need to go to http://www.sysdeo.com/eclipse/tomcatplugin.html to download the Tomcat plugin, and download it directly to the Plugins directory of Eclipse. After starting Eclipse, select "Customize Perspective ..." of the "Window" menu in the IDE, expand the Other node of the pop-up window, you can see the Tomcat option below, and hook "OK" close the window. After completing this step, there will be changes in the Ide toolbar, is it excited to see the lovely Tomcat kitten icon! But don't rush to press the kitten button, you need to go to "preferences" to do some settings correctly, select the Tomcat version you install, specify the Tomcat home directory and Tomcat's server.xml configuration file, and then expand Tomcat, choose the JVM Setting below, select JRE to "detected VM", confirm that you press "OK" to close the window. At this point, all the configuration work is finished, press the kitten icon to start Tomcat, you can see the Tomcat startup information such as "Starting Service Tomcat-Standalone ..." and other Tomcats appear.
After starting success, we do a simple servlet to test. Select the "Project" menu of the "file" below, Note To select "Tomcat Prject", press "Next" until the end, the service directory and other information according to the window prompt information, and select whether to update the Server. XML. For the sake of simplicity, we choose to automatically update the server.xml file, the virtual directory is the name servletdemo. Add your own servlet class, as an example, the author defines a simple TestServlet class to calculate 5! (5 steps) equal to how much, servlet code and web.xml Deployment Descriptor as follows:
Public class testservlet extends httpservlet {
Private static final string content_type = "text / html; charset = GBK";
Public void doget (httpservletRequest request, httpservletResponse response)
Throws servletexception, ioException {
Response.setContentType (Content_Type);
PrintWriter out = response.getwriter ()
INT n = 1;
For (INT i = 1; i <= 5; i ) {
N * = i;
}
Out.println ("");
Out.println ("
Out.println ("
Out.println ("
5! =" n " p>"); Out.println (" Body> HTML>");
Out.close ();
}
}
XML Version = "1.0" encoding = "UTF-8"?>
servlet>
servlet-maping>
web-app>
Save the above code and XML description file, type "http://127.0.0.1:8080/servletdemo/testservlet" in the browser, you can see "5! = 120", is it?
Below we set a breakpoint in "n * = i;", we will track the calculation process. Press the refresh button in the browser window and return to the Eclipsep window. Is there a blue bar in the line of breakpoint? The following procedure is familiar with the readers of Visual Age for Java, press F6 to track the next statement, press F5 to follow up the calling process.