Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
1
Indexable
Never
<%-- 
    Document   : makeTable
    Created on : 27-Feb-2020, 17:33:37
    Author     : o_molloy
--%>

<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Make a List</title>
    </head>
    <body>
             <h1>My ToDo List</h1>
       <% String item = request.getParameter("item");

            ArrayList<String> items = (ArrayList<String>) session.getAttribute("items");
            if (items == null)
            {
                items = new ArrayList();
            }

            if (items != null)
            {
                items.add(item);
                session.setAttribute("items", items);
            }

        %>

        <table border="1">
            <thead>
                <tr>
                    <th>Items</th>
                </tr>
            </thead>
            <tbody>

                
                
                <%  items = (ArrayList<String>) session.getAttribute("items");
                    if (items != null)
                    {
                        int len = items.size();

                        int i = 0;
                        for (i = 0; i < len; i++)
                        {
                %>

                <tr>
                    <td><%= items.get(i)%></td>
                </tr>
                <%
                        }
                    }
                %>
            </tbody>
        </table>

        <h1>Add A New Item To The ToDo List</h1>
        <form method="get">
            <label>Thing to do:</label>
            <input type="text" name="item"><br>
            <input type="submit" value="Add" >
        </form>
    </body>
</html>