JavaServer Pages (JSP) and JSTL – trouble with JSPs and forms

Hi, I am working on the my final project for my 3rd java class. We have learned servlets, and JSPs. I need to save all of the information into a database. The problem I am having is how to make all the form information only submit on the final page. I have made a jsp which shows a different ‘page’ depending on the page1, page 2 boolean values. If page1 = true; then page1 is showing, if page2 = true; page 2 is showing. The problem I’m having is how to change the boolean values when the person hits the first next button. (I currently have it as a sumit button because I don’t know how to get to the second page). Any help or thougts on this matter would be appreciated. thanks.

Here is part of the code”

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%! private Boolean _page1 = true; %>
<%! private Boolean _page2 = false; %>
<html>
<jsp:useBean id="resume" class="Sheridan.Resume"/>
<jsp:setProperty name="resume" property="*"/>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
    <title>ResumeBuilder</title>
  </head>
  <body>
    <form name="input" action="sheropolisservlet" method="post">
      <% if (_page1 == true)
  {%>
      <p>Personal Information</p>
      <p>Name:</p>
      <table cellspacing="2" cellpadding="3" border="1" width="100%">
        <tr>
          <td width="13%">First Name:</td>
          <td width="87%">
            <input type="text" name="_firstName" maxlength="20" size="20"/>
          </td>
        </tr><tr>
          <td width="13%">Last Name:</td>
          <td width="87%">
            <input type="text" name="_lastName" maxlength="20" size="20"/>
          </td>
        </tr><tr>
          <td width="13%">Middle Initial:</td>
          <td width="87%">
            <p>
              <input type="text" name="_middleInitial" maxlength="1" size="1"/>
            </p>
          </td>
        </tr>
      </table>
      <p>Address:</p>
      <table cellspacing="2" cellpadding="3" border="1" width="100%">
        <tr>
          <td width="50%">
            <p>Street Number and Name:</p>
          </td>
          <td width="50%">
            <input type="text" name="_street" maxlength="20" size="20"/>
          </td>
        </tr><tr>
          <td width="50%">City:</td>
          <td width="50%"> </td>
        </tr><tr>
          <td width="50%">Province:</td>
          <td width="50%"> </td>
        </tr><tr>
          <td width="50%">Postal Code:</td>
          <td width="50%"> </td>
        </tr><tr>
          <td width="50%">Country:</td>
          <td width="50%"> </td>
        </tr>
      </table>

      <p>
        <a href="http://127.0.0.1:7101/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">RESET</a>
      </p>

      <p>
        <input type = "submit" value = "NEXT">
      </p>
      <%}%>

      <% if (_page2 == true)
  {%>
      <p>Employment Objective:</p>
      <p>Career Objective:</p>
      <p>Programming Languages:</p>
      <p>Operating Systems:</p>
      <p>Responsibilities:</p>
      <p>Software Development Areas:</p>
      <p> </p>
      <a href="http://127.0.0.1:7101/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">RESET</a>
      <a href="http://127.0.0.1:7101/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">PREVIOUS</a>
      <input type="submit" value="Save"/>
      <%}%>
      <p>
        <a href="http://127.0.0.1:7101/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">HOME</a>
      </p>
    </form>
  </body>
</html>

My suggestion is fairly straightforward.
 If you have two pages, then it should be two seperate jsp pages, not one jsp page which conditionally displays one page or the other.
 Your servlet should be responsible for directing to the correct by using a RequestDispatcher to forward to the appropriate jsp to display a result.
 Have you covered the MVC (Model-view-controller) pattern in your class?

 The URLs in your page are hardcoded to your machine: <a href="http://127.0.0.1:7101/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">HOME</a>

 I would suggest that you use a website relative link.  
 ie: <a href="/Sheropolis-Michelle-Project1-context-root/ResumeBuilderForm2.html">HOME</a>
 or even better
 <a href="${pageContext.request.contextPath}/ResumeBuilderForm2.html">HOME</a>

 If you have a multiple jsp page "wizard" then you probably want to store state in the session - probably in a java bean.
 It would be easier to use javabeans if you didn't name all your fields starting with _.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image