JavaBeans Form的问题

时间:2009-12-06 18:15:48

标签: java forms jsp javabeans

我有一项使用JavaBeans创建在线银行应用程序的任务。我正在尝试制作注册表单,但我遇到了一些问题。当表单提交时,我无法获取值。

表格:

<jsp:include page="header.html"></jsp:include>

<h3>Create An Account</h3>
    <form action="process_new_user_account.jsp" method="post"  onsubmit="return validate_form(this)" >
    <fieldset>
        <legend>Personal Info</legend>

    <table width="650px" border="0" align="center">
      <tr>
        <td width="25%"><div align="right">First Name: </div></td>
        <td width="75%">
            <input type="text" onblur="return validate_field(this)" onchange="return validate_field(this)"  onfocus="return validate_field(this)" name="fname" tabindex="1" size="50"/>
        </td>
      </tr>
      <tr>
        <td><div align="right">Last Name: </div></td>
        <td><input type="text" onblur="return validate_field(this)" onchange="return validate_field(this)"  onfocus="return validate_field(this)" name="lname" tabindex="2" size="50"/></td>
      </tr>
      <tr>
        <td><div align="right">Address:</div></td>
        <td><input type="text" onblur="return validate_field(this)" onchange="return validate_field(this)"  onfocus="return validate_field(this)" name="streetAddress" tabindex="3" size="50"/></td>
      </tr>
      <tr>
        <td><div align="right">City:</div></td>
        <td><input type="text" onblur="return validate_field(this)" onchange="return validate_field(this)"  onfocus="return validate_field(this)" name="city" tabindex="4" size="50"/> </td>
      </tr>
          <td><div align="right">State:</div></td>
          <td>
             <select name="state" style="width: 300px;" tabindex="5" onblur="return validate_field(this)" onchange="return validate_field(this)"  onfocus="return validate_field(this)">
                <option value="">Select A State</option>
                <option value="AL" >Alabama</option>
                <option value="AK" >Alaska</option>
                <option value="AZ" >Arizona</option>
                <option value="AR" >Arkansas</option>
                <option value="CA" >California</option>
                <option value="CO" >Colorado</option>
                <option value="CT" >Connecticut</option>
                <option value="DE" >Delaware</option>
                <option value="DC" >District of Columbia</option>
                <option value="FL" >Florida</option>
                <option value="GA" >Georgia</option>
                <option value="HI" >Hawaii</option>
                <option value="ID" >Idaho</option>
                <option value="IL" >Illinois</option>
                <option value="IN" >Indiana</option>
                <option value="IA" >Iowa</option>
                <option value="KS" >Kansas</option>
                <option value="KY" >Kentucky</option>
                <option value="LA" >Louisiana</option>
                <option value="ME" >Maine</option>
                <option value="MD" >Maryland</option>
                <option value="MA" >Massachusetts</option>
                <option value="MI" >Michigan</option>
                <option value="MN" >Minnesota</option>
                <option value="MS" >Mississippi</option>
                <option value="MO" >Missouri</option>
                <option value="MT" >Montana</option>
                <option value="NE" >Nebraska</option>
                <option value="NV" >Nevada</option>
                <option value="NH" >New Hampshire</option>
                <option value="NJ" >New Jersey</option>
                <option value="NM" >New Mexico</option>
                <option value="NY" >New York</option>
                <option value="NC" >North Carolina</option>
                <option value="ND" >North Dakota</option>
                <option value="OH" >Ohio</option>
                <option value="OK" >Oklahoma</option>
                <option value="OR" >Oregon</option>
                <option value="PA" >Pennsylvania</option>
                <option value="RI" >Rhode Island</option>
                <option value="SC" >South Carolina</option>
                <option value="SD" >South Dakota</option>
                <option value="TN" >Tennessee</option>
                <option value="TX" >Texas</option>
                <option value="UT" >Utah</option>
                <option value="VT" >Vermont</option>
                <option value="VI" >Virgin Islands</option>
                <option value="VA" >Virginia</option>
                <option value="WA" >Washington</option>
                <option value="WV" >West Virginia</option>
                <option value="WI" >Wisconsin</option>
                <option value="WY" >Wyoming</option>
            </select>           </td>
        </tr>
        <tr>
          <td><div align="right">Zip:</div></td> 
          <td><input name="zip" type="text" id="zip" tabindex="6"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
        </tr>
      <tr>
        <td><div align="right">Phone:</div></td>
        <td> <input name="phone" type="text" id="phone" tabindex="7"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
      </tr>
      <tr>
        <td><div align="right">Email:</div></td>
        <td><input name="email" type="text" id="email" tabindex="8"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
      </tr>   
</table>

    </fieldset>

    <fieldset>
        <legend>Login Info</legend>

        <table width="650px" border="0" align="center">
      <tr>
        <td width="25%"><div align="right">Username:</div></td>
        <td width="75%"><input name="username" type="text" id="username" tabindex="9"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
      </tr>
      <tr>
        <td><div align="right">Password:</div></td>
        <td><input name="password" type="password" id="password" tabindex="10"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
      </tr>   
      <tr>
        <td><div align="right">Reenter Password: </div></td>
        <td><input name="passwordRE" type="password" id="passwordRE" tabindex="11"  onblur="return validate_field(this)" onfocus="return validate_field(this)" onchange="return validate_field(this)" size="50"/></td>
      </tr>                       
    </table>
    </fieldset>

        <div align="center">
          <input type="reset" name="Reset" value="Clear" />
          <input type="submit" name="Submit" value="Create Account" tabindex="12" />
        </div>

    </form>

    <br /><br />

       <jsp:include page="footer.html"></jsp:include>

提交给的JSP页面(它只是用于测试的简短页面,直到我开始工作):

<%@page import="WebBank.Customer"%>
<jsp:useBean id="customer" scope="session" class="WebBank.Customer"/>
<jsp:setProperty name="customer" property="zip"/>


<jsp:include page="header.html"></jsp:include>

<h3>Welcome!</h3>
<p>Thank you for creating a new account with JAC Bank!</p>


<%
 System.out.println("Testing.....");
 System.out.println("Name: " + customer.getZip());
 %>

<jsp:include page="footer.html"></jsp:include>

还有一个名为Customer的类,它有一个默认构造函数和一个String getZip()和void setZip(String zip)方法。

1 个答案:

答案 0 :(得分:0)

我没有看到servlet从输入表单中解压缩值,将它们绑定到Customer对象,然后将其添加到会话中。你的代码中会发生什么?

它被称为Model-2 MVC。添加一个servlet和漏斗请求。你会更好。

我还建议您学习JSTL并从JSP中删除所有scriptlet代码。