Creating a servlet in an Eclipse Dynamic Web Project

Home > Search
  by

This assumes you have created your first dynamic web project in Eclipse

  1. In the left panel of Eclipse, expand the Java Resources folder, right click on the src folder, and select New > Package.
  2. Give the package a name, such as com.main.servlet and select Finish.
  3. Right click on the newly created package and select New > Servlet.
  4. Give the servlet a name, such as myServlet, and select Finish.
  5. In the doGet method section of the markup, add the following.
  6. In your index.html file, add the following to the body.

 

System.out.println("Go to <a href='http://localhost:8080/myApp'>Home page</a>");
  1. Add the following to your index.html page.

 

Go to <a href='http://localhost:8080/myApp/myServlet'>Home page</a>

 

 

Run the application in Eclipse, or export the WAR and run the application on an application server. Now, when navigating to index.html, there will be a link to the servlet.

 

Clicking the button will redirect to the servlet you created.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments