logo

Example Of Creating Servlet In Eclipse


Show

Eclipse is an open Source for creating JavaSE and JavaEE (J2EE) applications. Eclipse ide can be downloaded from the Eclipse website.

http://www.eclipse.org/downloads/.

Eclipse ide can be downloaded for JavaEE developers.

Creating a servlet instance in eclipse ide saves a whole lot of work to be done. It is straightforward and easy to create a servlet instance. Let's see the steps you want to observe to create the primary servlet instance.

  • Create a Dynamic net project
  • Make a servlet
  • upload servlet-api.jar file
  • Run the servlet

1.Create the dynamic web project:

You can create a dynamic web project with the following given example: click on File Menu option -> tap on New ->then Project.. option-> Web -> dynamic web project -> Now, write your project name e.g. first -> Finish.

2. Create the servlet in eclipse IDE:

Steps to create a servlet, explore the project by clicking the + icon -> explore the Java Resources -> right click on src -> New -> servlet -> write your servlet name e.g. Hello -> uncheck all the checkboxes except doGet() -> next -> Finish.

3.Now, add jar file in Eclipse IDE

For adding a jar file, right click on your project -> Build Path -> Configure Build Path -> click on Libraries tab in Java Build Path -> click on Add External JARs button -> select the servlet-api.jar file under tomcat/lib -> ok.

4.Start the server and deploy the project

Deploy the project in one step, for starting the server Right click on your project -> Run As -> Run on Server -> choose tomcat server -> next -> addAll -> finish.

The Tomcat Server is being started and the project is deployed. Write the Url pattern name in the Url bar of the browser, to access the servlet. In this below given case hello then enter

How to configure Tomcat server in Eclipse? (One time Requirement)

You need to configure the tomcat server first if you are using the Eclipse IDE for the first time.

Follow the given steps for configuring the Tomcat Server in eclipse IDE, click on servers tab at the bottom side of the IDE -> right click on blank area -> New -> Servers -> choose tomcat then its version -> next -> click on Browse button -> select the apache tomcat root folder previous to bin -> next -> addAll -> Finish.

Now, the tomcat Server has been configured in Eclipse IDE.