Servlet Labs
In this lab we will change the output of an existing dynamic webapp and deploy it to Tomcat.
- In
JavaWebIntro/src/main/webapp/index.html, add a link toinventorywith the textList Inventory. -
Note: the link's destination is not
inventory.htmlor/inventory. -
In
JavaWebIntro/src/com.example.javaweb.labs.InventoryServlet: -
After
<body>, add ah1header to the output stream, that saysInventory. UseHelloWorldServletas an example for adding HTML to the response.pw.println(" <h1>Inventory</h1>"); -
Add the products to the response as an unordered list.
pw.println("<ul>"); for (String s : inventory) { pw.println("<li>"); pw.println(s); pw.println("</li>"); } pw.println("</ul>"); -
Run the project on the Tomcat server and access the servlet via
index.html. -
(Optional) Add Bootstrap configuration in the output's
<head>, and place the content in a<div class="container">.
(Solution: JavaWebIntro/src/main/webapp/index2.html, JavaWebIntro/src/com.example.javaweb.solutions.labs.InventoryServlet )