Create the first servlet program in eclipse

Source: Internet
Author: User

This article from: http://kin111.blog.51cto.com/738881/163354

 

After setting up the Tomcat environment in eclipse in the previous article, we established a simple servlet program, which simply outputs helloworld.

The procedure is as follows:
Select create a project in eclipse, and select Tomcat Project

Click Next, enter the project name, and click Next,

The following figure shows the settings of the next project,

Click Finish.
Open the project on the left of eclipse, and you can see that the created servlet project has appeared.

Okay, basically we have done it. The rest is to create two files,
A file is the helloworldservlet. Java file, placed under the WEB-INF/src,
Content:
Import java. Io .*;

Import javax. servlet. http .*;
Import javax. servlet .*;

Public class helloworldservlet extends httpservlet {
Public void doget (httpservletrequest req, httpservletresponse res)
Throws servletexception, ioexception {
Printwriter out = res. getwriter ();
Out. println ("Hello, brave new world! ");
Out. Close ();
}
}

The Web. xml file for another file, placed under the WEB-INF,
Content:
<! Doctype web-app public
'-// Sun Microsystems, Inc. // DTD web application 2.3 // en'
'Http: // java.sun.com/dtd/web-app_2_3.dtd'>
<Web-app>
<Servlet>
<Servlet-Name> Hello </servlet-Name>
<Servlet-class> helloworldservlet </servlet-class>
</Servlet>

<Servlet-mapping>
<Servlet-Name> Hello </servlet-Name>
<URL-pattern>/Hello </url-pattern>
</Servlet-mapping>
</Web-app>

Reference

Finally, click the start Tomcat button of the kitten to check from the console that the Tomcat server is started normally,
Open your browser and enter http: // localhost: 8080/helloworldservlet/Hello
"Hello, brave new world!" is displayed !" .

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.