New project: Select Tomcat Project, project name: Practice
In the SRC directory to create a new Java program, named Firstservlet.java, the code is as follows:
Import java.io.*; Import javax.servlet.*; Import javax.servlet.http.*; public class Firstservlet extends HttpServlet {public void service (HttpServletRequest request,httpservletresponse Response) throws IOException {PrintWriter out=response.getwriter (); Out.print ("My-A-servlet!");}
The simplest code for creating a new Web.xml file in Web-inf is as follows:
<web-app> <servlet> <servlet-name>myfirst</servlet-name> <servlet-class> firstservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>myfirst</ servlet-name> <url-pattern>/yeah</url-pattern> </servlet-mapping> </web-app>
Ok. Run Tomcat and view it in the browser using the following path: Http://localhost:8080/Practice/yeah
Success.