Let's see the steps, you need to follow to create the first servlet example.
- Create a Dynamic web project
- create a servlet
- add servlet-api.jar file
- Run the servlet
- Create the dynamic web project:
For creating a dynamic web project
click on
File Menu -> New -> Dynamic web project -> write your project name e.g. first -> Finish. - Create the servlet in eclipse IDE:
For creating a servlet, explore the project by
clicking the + icon -> explore the Java Resources -> right click on project or application -> New -> servlet -> write your servlet name
e.g. Hello -> uncheck all the checkboxes except doGet() -> next -> Finish. - 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. - 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.