Install Tomcat plug-in eclipse

Source: Internet
Author: User

I. Software Download

    • Eclipse3.6 IDE for Java EE developers: http://eclipse.org/downloads/
    • Tomcat eclipse Plugin: http://www.eclipsetotale.com/tomcatPlugin.html

Ii. software installation and configuration (image and text)

1. Decompress eclipse to a directory, such as/usr/local/eclipse.

2. decompress the Tomcat plug-in to the Plugins directory under the eclipse directory.

3. If your JDK isJkd1.6.0 _ 21 and later versionsThe out of memory problem may occur when eclipse is started. The solution is to add a line in the eclipse. ini file:-XX: maxpermsize = 256 m.
4. Start eclipse and configure tomcat. Windows-> preferences, find the Tomcat option: Select tomcat version (no 7.0, select 6. x), and then configure the tomcat installation directory, such:

5. Configure the server option, find server-> Server Runtime Environment, and create a new server:

Finally, OK completes the Tomcat and eclipse settings. Normally, three Tomcat buttons are added to the interface. If not, choose windows> custmize perspective to expand the other option and check tomcat.

3. Create a servlet TestProgram

1. Start eclipse and select the menuFile-> New-> project...In the new project wizard, selectWeb-> dynamic web project. This project is a project that uses servlet, JSP, and other technologies to develop dynamic websites.

2. Simple Project Settings: Create a project: helloworld. You can set it in the specific section:

3. In project explorer on the left side of Eclipse, right-clickJava resources: SRCDirectory (hereinafter referred toSRCDirectory), selectNew-> class, Create the following class

Package name: Enter the com. idv2.learnjsp to be created. The class name is helloservlet, and the parent class is javax. servlet. http. genericservlet. When entering the parent class name, you will see a light bulb icon on the left side of the input box.Alt -/The key is automatically completed, so you only need to enter several letters of genericser and press Alt-/. The system will automatically search for the class starting with genericser and complete the remaining parts.

After completion, eclipse will generateCodeFramework. You only need to enter the actual processing code.

Package COM. idv2.learnjsp; import Java. io. ioexception; import Java. io. printwriter; import javax. servlet. genericservlet; import javax. servlet. servletexception; import javax. servlet. servletrequest; import javax. servlet. servletresponse; public class helloservlet extends genericservlet { /*** Automatically generated serial number */ Private Static final long serialversionuid = 322156425287226122l; /*** Functions called at servlet startup */ Public void Init () {System. Out. println (" Init () was called. ");} /*** Process client requests * @ Param req client request * @ Param res client response */ @ Overridepublic void Service (servletrequest req, servletresponse res) throws servletexception, ioexception {system. Out. println ("Service () was called. "); // Specify the output content and encoding method Res. setcontenttype (" Text/html; charsets = UTF-8 "); // Get the output stream object Printwriter out = res. getwriter (); // Send HTML content Out. println (" <HTML> "); Out. println (" <Head> "); Out. println (" <Title> hello, Servlet! </Title> "); Out. println (" </Head> "); Out. println (" <Body> "); Out. println ("Hello, Servlet! "); Out. println (" </Body> "); Out. println (" </Html> ");} /*** Functions called at servlet end */ Public void destroy () {system. Out. println (" Destroy () was called. ");}}

4. In wecontent/WEB-INF/Web. XML, configure

<? XML version =" 1.0 "Encoding =" UTF-8 "?> <Web-app xmlns: xsi =" Http://www.w3.org/2001/XMLSchema-instance "Xmlns =" Http://java.sun.com/xml/ns/javaee "Xmlns: Web =" Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "Xsi: schemalocation =" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "Id =" Webapp_id "Version =" 2.5 "> <Servlet-Name> helloservlet </servlet-Name> <servlet- Class > Com. idv2.learnjsp. helloservlet </servlet- Class > </Servlet> <servlet-mapping> <servlet-Name> helloservlet </servlet-Name> <URL-pattern>/helloservlet </url-pattern> </servlet-Mapping> </Web-app>

right-click the server and choose Start from the shortcut menu. a large amount of information is output in the console and the server is started. Open your browser and access http: // localhost: 8080/learnjsp/helloservlet. If you can see the output of "Hello servlet", congratulations! The first servlet is successfully running!

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.