Skip to Content
Previous

Adding a simple web page to a Java app

By akula86

Adding a simple web page to a Java app

You will learn

In this tutorial you will learn how to add a basic HTML page to a Java app.

Details


Step 1: Create a new HTML page

Navigate to the webapp node in the Project Explorer and create a new HTML page by selecting the respective context menu entry: New > HTML File.

Choose the name index.html and click on Finish.

Creating a new HTML file
Please log in to access this content.
Step 2: Add body

Add the following line of code in between the opening and the closing tag:

<p>Hello World!</p>
Editing the body of the HTML file
Please log in to access this content.
Step 3: Save and publish locally

Save your changes and publish the update project to the local server by selecting the respective context menu on the server in the Server view.

Please log in to access this content.
Step 4: View app

Once the publishing is done you can go back to the internal browser window and remove the /hello part of the URL and hit the Enter key. Now, you should see the same “Hello World!” message for the URL http://localhost:8080/weatherapp/ as well. The reason for this is the <welcome-file-list> in the web.xml (located in the WEB-INF directory underneath the webapp folder).

Run the java app, but use the base URL, not the servlet
Please log in to access this content.
Step 5: Clean up entries

For security reasons and for the sake of housekeeping you should remove all entries except for the index.html entry from the web.xml file.

Editing web.xml to remove welcom-file entries
Please log in to access this content.

Next Steps

Updated 03/24/2017

Time to Complete

5 min

Intermediate

Tags

Next
Back to top