我在jsp页面中为我的表单使用html5验证。我在表格中给出了无效。当我点击该表单的提交按钮时,它应该立即验证表单并在之前隐藏的一个标签中显示所有验证。如何在jsp中获取这些? 这是我的表格代码。
<form action="#join1_form" method="POST">
<div>
<input type="text" name="firstname" id="firstname" value="" required placeholder="First Name" pattern="\w+" />
<input type="text" name="lastname" id="lastname" value="" required placeholder="Last Name" pattern="\w+" />
</div>
<div>
<input type="email" name="email" placeholder="Your Email" id="email" value="" required />
</div>
<div>
<input name="password" id="password" type="password" required placeholder="New Password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" name="password" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Password must contain at least 6 characters, including UPPER/lowercase and numbers' : '');
if(this.checkValidity()) form.cpassword.pattern = this.value;">
</div>
<div>
<input name="cpassword" id="cpassword" type="password" placeholder="Re-enter Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" name="cpassword" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');">
</div>
<div>
<input type="label" hidden value="">
</div>
<input type="submit" value="Next">
</form>
我想在提交提交按钮后显示所有验证说明。这些验证应显示在文本字段中,隐藏在这里。我可以这样做吗?
这是我不重复emailID的代码。我应该把它放在上面的表格中?如何在上面隐藏的文本字段中显示其验证?
<%
Connection conn = null;
PreparedStatement ps=null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "");
String email1=request.getParameter("lemail");
try{
String q="SELECT * FROM userdetails where email=?";
ps=conn.prepareStatement(q);
ps.setString(1,email1);
rs=ps.executeQuery();
if(rs.next())
{
//what to do here?
}
else
{
//what to do here?
}
}
catch(Exception e)
{
e.printStackTrace();
}
try{
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
答案 0 :(得分:1)
<html:form action="storenotes" onsubmit="return demo()">
在JavaScript中调用demo()函数 并提交表格 返回true 要么 返回错误