Step 5: Add a JSP Page

In this step we will add the JSP that generates the guestbook page output:

  • Open the [New JSP File] dialog box by right clicking the WebContent node (in the [Package Explorer] window), selecting New > Other... > Web > JSP File and clicking Next.
  • Enter guest as the jsp file name - use exactly that case sensitive class name.
  • Click Finish to create the new JSP file.

Now replace the content of the new jsp file with the following content:

<%@page contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,guest.Guest"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>JPA Guest Book Web Application Tutorial</title>
    </head>

    <body>
        <form method="POST" action="GuestServlet">
            Name: <input type="text" name="name" />
            <input type="submit" value="Add" />
        </form>

        <hr><ol> <%
            @SuppressWarnings("unchecked") 
            List<Guest> guests = (List<Guest>)request.getAttribute("guests");
            for (Guest guest : guests) { %>
                <li> <%= guest %> </li> <%
            } %>
        </ol><hr>
 
        <iframe src="http://www.objectdb.com/pw.html?web-eclipse"
            frameborder="0" scrolling="no" width="100%" height="30"> </iframe>
     </body>
 </html>

The JSP generates the guestbook page output, which contains a simple form for signing the guestbook, followed by a list of all the guests that have already signed (which are retrieved from the request's "guests" attribute that is set by the servlet in the previous step).

The next step (and the last one in this tutorial) is running the web application.