JSP中如何写密码输入和确认密码时正确与否的Java判断代码?

JSP中如和写密码输入和确认密码的正确还是不同的Java代码?

jsp中判断两次输入的密码是否相同的方法是通过js实现的。
在两个文本框里添加onchange事件,在文本框的内容一发生变化时就触发该事件,而判断就写在这个事件之内就可以了。

<script language="javascript" type="text/javascript">
function check()
{

if (document.form1.username.value==""){
alert("请输入登录账号!");
return false;
}
if (document.form1.passwords.value==""){
alert("请输入登录密码!");
return false;
}
if (document.form1.password.value==""){
alert("请输入重复密码!");
return false;
}
if (document.form1.password.value!=document.form1.passwords.value){
alert("对不起!重复密码不等于登录密码");
return false;
}

return true;

}
</script>

<input type="submit" value="确定添加" onClick="return check()">
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-07-31
这个一般在前台用JAVASCRIPT代码写 不需要在后台用JAVA代码 <p>
密码<input type="password" name="Password" class="input1"id="mima1" />
<BR>
确认密码<input type="password" name="PwdConfirm" class="input1" id="mima2"/>
<BR>
<input type="button" value="确认"onclick="panduan()"></p> //Js脚本部分
<script type="text/javascript">
function panduan()
{
var mima1=document.getElementById("mima1").value
//取出第一个文本框里输如的值密码一
var mima2=document.getElementById("mima2").value
//取出第二个文本框里输如的值密码二
if(mima1==mima2)
//2个值比较,做判断
{
alert("2个密码一样拉")
//输出对话框提示
document.getElementById("mima1").focus()
//焦点定位
}
else
//否则
{
alert("密码和密码确认不同,请重新输入")
//输出对话框提示
document.getElementById("mima1").focus()
//焦点定位
}
}
</script>
第2个回答  2013-07-31
登录页面login.jsp,登录后提交到servlet验证<form name="login" action="LoginServlet"><TABLE width="100%" style="cellpadding: 0px; cellspacing: 0px; margin-top: 0px; margin-Left: 0px" style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word">
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%">
用户名:
</TD>
<TD style="color:#4c4743;line-height:160%;" valign="top">
<input type="text" name="userName" />
</TD>
</TR>
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%">
密 码
</TD>
<TD style="color:#4c4743;line-height:160%;" valign="top">
<input type="text" name="password" />
</TD>
</TR>
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%">
<input type="submit" value="提交" />
</TD>
<TD style="color:#4c4743;line-height:160%;" valign="top">
<input type="reset" value="重置" />
</TD>
</TR>
</TABLE></form> LoginServlet验证:public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=GBK");
String userName=request.getParameter("userName");
String password=request.getParameter("password");
Users users=new Users(userName,password);
UserBo userbo=new UserBo();
if(userbo.checkLogin(users)){
HttpSession session=request.getSession();
session.setAttribute("users", users);
response.sendRedirect("SelectServlet");
}else{
String script = "<script>alert('用户名或密码错误,请重新登陆');location.href='index.jsp'</script>";
response.getWriter().println(script);
}
}
第3个回答  2016-02-13
jsp中判断两次输入的密码是否相同的方法是通过js实现的。
在两个文本框里添加onchange事件,在文本框的内容一发生变化时就触发该事件,而判断就写在这个事件之内就可以了。
第4个回答  2017-06-28
这个问题是你注册时输入两次密码遇到的问题? 那么最普通的方案就是写js验证了
相似回答