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 !" .