1. 首页
  2. 资讯

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

登录页面login.jsp,登录后提交到servlet验证<formname="login"action="LoginServlet"><TABLEwidth="100%"style="cellpadding:0px;cellspacing:0px;margin-top:0p

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

登录页面login.jsp,登录后提交到servlet验证<formname="login"action="LoginServlet"><TABLEwidth="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>

<TDstyle="color:#4c4743;line-height:160%;"valign="top"

width="30%">

用户名:

</TD>

<TDstyle="color:#4c4743;line-height:160%;"valign="top">

<inputtype="text"name="userName"/>

</TD>

</TR>

<TR>

<TDstyle="color:#4c4743;line-height:160%;"valign="top"

width="30%">

密码

</TD>

<TDstyle="color:#4c4743;line-height:160%;"valign="top">

<inputtype="text"name="password"/>

</TD>

</TR>

<TR>

<TDstyle="color:#4c4743;line-height:160%;"valign="top"

width="30%">

<inputtype="submit"value="提交"/>

</TD>

<TDstyle="color:#4c4743;line-height:160%;"valign="top">

<inputtype="reset"value="重置"/>

</TD>

</TR>

</TABLE></form>LoginServlet验证:publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)

throwsServletException,IOException{response.setContentType("text/html;charset=GBK");

StringuserName=request.getParameter("userName");

Stringpassword=request.getParameter("password");

Usersusers=newUsers(userName,password);

UserBouserbo=newUserBo();

if(userbo.checkLogin(users)){

HttpSessionsession=request.getSession();

session.setAttribute("users",users);

response.sendRedirect("SelectServlet");

}else{

Stringscript="<script>alert('用户名或密码错误,请重新登陆');location.href='index.jsp'</script>";

response.getWriter().println(script);

}

}

本文来自投稿,不代表本站立场,如若转载,请注明出处。