Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaEE: Create Dynamic Web Project With Tomcat And Eclipse

Monday, September 16, 2019

JavaEE: Create Dynamic Web Project With Tomcat And Eclipse

In order to host websites in Tomcat we need to create a project to host servlets.  In this post we are going to create Dynamic Web project in Eclipse.

Here are the steps to create a web project in Eclipse:

1. Right-click on "Servers" → "New" → "Other"

2. Expand the "Web" node then select "Dynamic Web Project", then click "Next"→





























3.  Give the project a name then click "Next", then "Next" again



4. When you get to the "Web Module" screen, check the "Generate web.xml deployment descriptor" checkbox.

  5. A Web application call StockTickers has been created

  6. Now let's create a servlet to test out our web application, to create a servlet Right-click on the "StockTickers" project then click "New"→"Servlet".  Change the superclass to javax.servlet.GenericServlet then click "Finish"







A new servlet file will be created, in the StockTickers project

7.  In the service method type in the following code just to test out our application


 public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  
  PrintWriter out = response.getWriter();
  out.println("Hello stocks");
 }


8. Click on the "Run" menu then click on "Run" again

9.  When you see "Run On Server" screen accept the default and check "Always use this server running this project"



You will see that we've just created a web application on Tomcat call StockTickers on port 8080











1 comment:

Search This Blog