Create and Run a Dynamic Web Application in Java

In one of the previous tutorial, we have learned about how to setup environment for Java web application development and two common problems related to it. In this tutorial we will learn how to start developing web application using eclipse IDE. There are simple steps to follow. First, we will create a dynamic web application project. Then we will create an HTML file in the created project and Configure it with our web application and the final step is to run the project on the Server.

  1. Create a dynamic web application project

 

Create a new other server project in eclipse
Create a new other server project in eclipse

1 – Right-click on the server in the project explorer tab (the server will be there if you have successfully completed our previous tutorial).

2 – click on New.

3 – click on Other.

New dynamic web project
New dynamic web project

4 – In the opened window as the search for “Web” and expand it.

5 – From the Expanded list, select Dynamic Web Project.

6 –  Now click Next.

New dynamic web project name
New dynamic web project name

7 – Type the Project Name.

8 – Click Next.

9 – On clicking next a new window will be opened just click Next.

10 – Another window will be opened here just click finish and your project will be created.

 

  1. Create an HTML file
add new HTML file in web content
Add a new HTML file in web content

11 – Expand your project in the Navigator tab or Project Explorer tab now search for Web Content Right click on the Web Content.

12 – Click on New.

13 – Click on Other.

HTML file from web drop down in web content
HTML file from the web drop down on web content

14 – Again search for “Web” in the opened window and expand it.

15 – In the expanded list you will see the “HTML File” List item, Select it.

16 – Click Next.

select parent folder for HTML file
Select parent folder for HTML file

17 – Step 16 sill open the new window, this window is for selecting the directory to create an html file in it, here select “Web content”.

18 – In  “File name” type index.html.

19 – Click Finish.

index.html file in web content, Java EE
index.html file in web content, Java EE

20 – You have successfully created the HTML File in the “Web Content” Folder as shown in figure.

Change HTML according to your needs.

 

  1. Configure HTML with your web application
configure HTML file in web.xml
Configure HTML file in web.xml

21 – In the Navigator tab or Project Explorer tab to expand “Web Content“ and then expand  “WEB-INF” there will be a web .xml file in it

22 –Open this “web.xml” file

23 – As index.html is  already configured,  in the opened file you will see in the  “welcome-file-list” tag  remove other configurations as they are not needed for now shown in figure.

 

  1. Run the project on the Server

    Run Java web project on server
    Run Java web project on server

 

24 – Right click on the project in the Navigator tab or Project Explorer tab.

25 – Click “Run As”.

26 – Now click “Run on server”.

Select server to run Java web project
Select server to run Java web project

27 – Select the server from “Run on server Window”, in our case it will be Tomcat as we have installed in the previous tutorial.

28 –Click finish.

29 –It will automatically open the web application tab in which the output of your index.html file will be displayed by the server.

open localhost from running server
open localhost from running server

30 –Select the link as shown in figure right click on the selection.

31 –And click “Delete” and press enter.

Tomcat localhost
Tomcat localhost

32 –previous step will open the server main page it means your server is now up and running, now we have successfully created and deployed our first web application project on the server.

Download Complete Servlets Project Here

In the next tutorial we will learn what a “Servlet” is and how to create a simple “Servlet” in our web application project.