第十一周--邮件系统补充一个注册一个登陆验证码
<body> <form action="dozhuce.jsp" method="post"> 账号:<input type="text" name="uuu"> <br> <br> 密码: <input type="text" name="ppp"> <br> <br> <input type="submit" value="注册"> </form> <a href="login.jsp">已有账号,直接登录</a> </body>
<body> <% request.setCharacterEncoding("utf-8"); String uuu=request.getParameter("uuu"); String ppp=request.getParameter("ppp"); Us u=new Us(); u.setZzhh(uuu); u.setMima(ppp); UsDao d=new UsDao(); d.insert(u); request.getRequestDispatcher("login.jsp").forward(request, response); %> </body>
<body> <form action="dologin.jsp" method="post"> 账号:<input type="text" name="username"> <br> <br> 密码: <input type="text" name="password"> <br> <br> 验证码: <input type="password" name="yzm" size="6"><br> <br> <% int yzm1=(int)( ((Math.random())*11) -1 ); int yzm2=(int)( ((Math.random())*11) -1 ); int yzm3=(int)( ((Math.random())*11) -1 ); int yzm4=(int)( ((Math.random())*11) -1 ); String yzmsum=yzm1+""+yzm2+yzm3+yzm4; %> <input type="hidden" name="mj" value="<%=yzmsum%>"> <img src="images/<%=yzm1%>.gif"> <img src="images/<%=yzm2%>.gif"> <img src="images/<%=yzm3%>.gif"> <img src="images/<%=yzm4%>.gif"> <br> <br> <input type="submit" value="登录"> </form> </body>
<body> <% String yzm=request.getParameter("yzm"); String yzm1=request.getParameter("mj"); String username=request.getParameter("username"); session.setAttribute("username", username); String password=request.getParameter("password"); UsDao d=new UsDao(); if( d.getLogin(username, password)&&yzm.equals(yzm1) ){ request.getRequestDispatcher("main.jsp").forward(request, response); }else{ response.sendRedirect("login.jsp"); } %> </body>