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"

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

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

        <hr><ol> <%
            List<Guest> guests = (List<Guest>)request.getAttribute("guests");
            for (Guest guest : guests) { %>
                <li> <%= guest %> </li> <%
            } %>
        <iframe src=""
            frameborder="0" scrolling="no" width="100%" height="30"> </iframe>

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.