在提交时重新填充具有自己值的文本框

时间:2015-10-14 07:04:39

标签: java jsp

所以我有这个“注册”表格,你必须填写你的帐户/个人信息。我对此进行了服务器端验证,但我希望文本框中填充的值与人们提交后填充的值相同(并且验证失败),例如“错误的电子邮件格式”,如果遗漏了@ ..

这是我的JSP页面的样子:

<form method="POST" action="Controller?theregform" id="regForm">
<tr>
    <td><label for="firstName">* First name</label></td>
    <td><input id="firstName" name="firstName" type="text" /></td>
</tr>
<tr>
    <td><label for="lastName">* Last name</label></td>
    <td><input id="lastName" name="lastName" type="text" /></td>
</tr>
<tr>
    <td><label for="email">* Email</label></td>
    <td><input id="email" name="email" type="email" required  /></td>
</tr>
<tr>
    <td><label for="repeatEmail">* Repeat Email</label></td>
    <td><input id="repeatEmail" name="repeatEmail" type="text" /></td>
    <td><input id="lblEmail" type="hidden"></td>
</tr>
<tr>
    <td><label for="phone">* Phone</label></td>
    <td><input id="phone" name="phone" type="text" /></td>
</tr>
<tr>
    <td><label for="address">* Address</label></td>
    <td><input id="adress" name="address" type="text" /></td>
</tr>
<tr>
    <td><label for="city">* City</label></td>
    <td><input id="city" name="city" type="text" /></td>
</tr>
<tr>
    <td><label for="adressCounty">* State</label></td>
    <td><input id="adressCounty" name="adressCounty" type="text" /></td>
</tr>
<tr>
    <td><label for="zipCode" >* Zip/Postal Code</label></td>
    <td><input id="zipCode" name="zipCode" type="text" /></td>
</tr>
<button type="submit" form="regForm"class="btn btn-success">Continue</button>

</form>

如果对问题不清楚,请使用评论部分,我会尝试更好地解释。

1 个答案:

答案 0 :(得分:1)

您可以使用EL(表达式语言)WITH x AS (SELECT 1 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 2 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 2 AS person_id, 'P O BOX 567' AS person_address, 'Home' AS TYPE FROM dual UNION ALL SELECT 3 AS person_id, 'post office 76' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 4 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 5 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 5 AS person_id, 'post office 76' AS person_address, 'Home' AS TYPE FROM dual UNION ALL SELECT 6 AS person_id, 'PO BOX 567' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 7 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 8 AS person_id, '5/40 The Avenu.' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 9 AS person_id, 'P O BOX 567' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 10 AS person_id, 'post office 76' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 11 AS person_id, 'PO BOX 567' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 12 AS person_id, '5/40 The Avenu' AS person_address, 'Mail' AS TYPE FROM dual UNION ALL SELECT 12 AS person_id, 'POST OFFICE 67' AS person_address, 'Mail' AS TYPE FROM dual ) SELECT x.* FROM x, (SELECT person_id, count(person_id) count_x FROM x GROUP BY person_id) y WHERE x.person_id = y.person_id AND count_x = 1 AND NOT REGEXP_LIKE (x.person_address, '(post office|PO BOX|POST OFFICE|P O BOX|[.])'); 重新填充表单字段:

 PERSON_ID PERSON_ADDRESS  TYPE
---------- --------------- ----
        1 5/40 The Avenu Mail 
        4 5/40 The Avenu Mail 
        7 5/40 The Avenu Mail 

您可以设置请求属性以显示错误消息。在验证码中,用于错误的电子邮件。

${param.fieldName}

在jsp页面中:

<input id="firstName" name="firstName" type="text" value="${param.firstName}"/>