❮ Previous Next ❯

How to create a Servlet in Eclipse IDE

Eclipse is an open-source IDE for developing JavaSE and JavaEE (J2EE) applications. We can download the eclipse IDE from http://www.eclipse.org/downloads/. We need to download the eclipse ide for JavaEE developers.

To develop a Servlet, we have to follow the following steps:

Step-1 : First click on File Menu -> New -> dynamic web project -> write your project name e.g. test -> then click next.

Step-2: Check Generate web.xml Deployment Descriptor and click Finish


Step-3: Now, the complete directory structure of your Project will be automatically created by Eclipse IDE.


Step-4: Click on test project, go to Java Resources -> src. Right click on src select New -> Servlet

Step-5: Give Servlet class name and click Next




Step-6: Then click next, then choose doGet() or doPost(), then click finish button




Step-7: Now our Servlet is created, we will write some code inside it.




Step-8 : then we will write web.xml(Deployment Descriptor file).

Dear frnds, here i want to inform web.xml file plays a very crucial role for execution of a servlet. So let’s know the detail first:

In Java web-based application, we use a web.xml file which is called as deployment descriptor file which represents how URL is mapping with Servlet. This file is under the WEB-INF/ directory. web.xml which is part of the Servlet standard for web applications. The file is an XML file whose root element is . A web application's deployment descriptor describes the classes, resources and configuration of the application and how the web server uses them to serve web requests.


<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
< servlet-name> abc </servlet-name>
<servlet-class> javarace.MyServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> abc </servlet-name>
<url-pattern> /MyServlet </url-pattern>
</servlet-mapping>
</web-app>

Step-9: then we will execute the servlet, i mean we will start the server and deploy the project. For starting the server and deploying the project in one step, Right click on your project -> Run As -> Run on Server -> choose tomcat server -> next -> addAll -> finish.

Now tomcat server has been started and project is deployed. To access the servlet write the url pattern name in the URL bar of the browser. In this case we will put MyServlet then enter. Then we will get the output Welcome 2 JavaRace


❮ Previous Next ❯

Follow Us





  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved