ObjectDB ObjectDB

Step 5: Add a JSP Page

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

  • Open the [New JSP File] dialog box by right clicking the WEB-INF node under the Web Pages node (in the [Projects] window) and selecting New > JSP...
  • Enter guest as the jsp file name - use exactly that case sensitive class name.
  • The Folder should be WEB-INF (to prevent accessing the JSP directly not through Spring).
  • 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="guest.*"%>

<jsp:useBean id="guestDao" type="guest.GuestDao" scope="request" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <title>JPA Guestbook Web Application Tutorial</title>

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

        <% for (Guest guest : guestDao.getAllGuests()) { %>
            <li> <%= guest %> </li>
        <% } %>

        <iframe src="http://www.objectdb.com/pw.html?spring-netbeans"
            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 guestDao attribute that is set by the controller in the previous step).

The next step (and the last in this tutorial) is setting the Spring XML configuration.