Skip to Content
Previous

End-to-End Weather App Scenario Part 2

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


  1. 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

  2. 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

  3. 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.

  4. 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

  5. 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

Next Steps

Updated 09/24/2016

Time to Complete

5 min

Intermediate

Tags

Next
Back to top