Tomcat plug-in installation and debugging on Eclipse

Source: Internet
Author: User
Tags tomcat apache tomcat

Visual age for Java is the Java IDE development environment developed by IBM. As early as a few years ago, it has accounted for half of the Java development platform, and it has been a long time since the new version, because IBM dedicated to the Eclipse Project research, many Java developers must have noticed this. Eclipse is a development source project that is actually an alternative to visual age for Java, with an interface similar to that of previous visual age for Java, but because of its open source, anyone can get it for free (official website in http:// www.eclipse.org/), and can develop their own plug-ins on this basis, so more and more people pay attention to. Many large companies, including Oracle, have recently joined the project, claiming that Eclipse will become an IDE synthesizer for any language development, and that users simply download plug-ins from a variety of languages.

And regardless of whether eclipse can be a true synthesizer, as far as the author's use of Java Java Development, eclipse has been very strong, much more powerful than the previous visual age-for, more Plug and Play, download a Tomcat plug-in, It's easy to invoke an externally-installed Apache Tomcat for JSP and servlet debugging. Let's see how easy it is for Eclipse plus tomcat to track the debug servlet.

We need to go to http://www.sysdeo.com/eclipse/tomcatPlugin.html to download the Tomcat plug-in, download it and unzip it directly into Eclipse's plugins directory. Then start eclipse, and in the IDE, select the "Window" menu "Customize perspective ..." to expand the other node of the pop-up window, you can see the Tomcat option below, and click "OK" to close the window. After this step, the IDE's toolbar will change, is not excited to see the cute Tomcat kitten icon it! But don't rush to press the kitten button, you need to go to the "Window" menu "preferences" to make some settings, the correct selection of your installed Tomcat version, Specify the Tomcat home directory and Tomcat's server.xml configuration file, then expand Tomcat, select the JVM Setting below, choose JRE as "detected VM", and then press "OK" to close the window after confirming the error. Here, all the configuration work is done, click the Kitten icon to start Tomcat, you can see? onsole window appears "Starting service tomcat-standalone ..." And so on Tomcat startup information.

After the startup is successful, we do a simple servlet test. Select the Project menu under the IDE's "File", note that you choose Tomcat prject, and then press "Next" until the end, in which information such as the servlet name, working directory, and so on, is entered according to the window prompts, and whether the Server.xml is automatically updated. For simplicity, we chose to automatically update the Server.xml file, the virtual directory as the name Servletdemo. Add your own servlet class to the project, as an example, the author defines a simple Testservlet class to compute 5! (factorial of 5) equals how much, the servlet code and the Web.xml deployment descriptor are 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, ioexcept   Ion {
Response.setcontenttype (content_type);
  PrintWriter out = Response.getwriter ()
int n = 1;
  for (int i = 1; i < = 5; i++) {
n *= i;

Out.println ("< html>");
Out.println ("< head>< title>testservlet</title> Out.println ("< body>");
Out.println ("< p>5! = "+ N + </p>");
Out.println ("</body> Out.close ();
}
< XML version= "1.0" encoding= "UTF-8"
<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.2//en" "Http://java.sun.com/j2ee/dtds/web-app_ 2_2.DTD
< Web-app>
< Servlet>
< servlet-name>testservlet</servlet-name>
< servlet-class>testservlet</servlet-class>
</ Servlet>
< Servlet-mapping>
< servlet-name>testservlet</servlet-name>
< Url-pat tern>/testservlet</url-pattern>
</servlet-mapping>
</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 ", isn't it?

Below we are in "N *= i;" The line sets a breakpoint to track the calculation process. Press the Refresh button in the browser window and return to the Eclipsep window, is there a blue bar on the breakpoint line? The following procedure is familiar to readers of visual age for Java should understand, press F6 to trace to the next statement, and follow the call process by F5.

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.