• 第九个JSP作业-注册验证


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">  
        <title>注册</title>   
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
      </head>  
      <body>
       <form action="do.jsp" method="post">
    用户名:<input type="text" name="uname"/><br>
    密   码:<input type="password" name="upwd"/><br>
    <input type="submit" value="注册">
    </form>
      </body>
    </html>
    

      

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        <title>登录</title>
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
      </head>
      <script type="text/javascript">
       function mycheck() {
    //判断验证码是否为空
     if (form1.validationCode.value==""){
    alert("验证码不能为空,请输入验证码!");
     form1.validationCode.focus();
     return;
     }
     //判断验证码是否正确
     if (form1.validationCode.value != form1.validationCode1.value) {
     alert("请输入正确的验证码!!");
     form1.validationCode.focus();
     return;
     }
     form1.submit1();
     }
     </script>
      <body>
       <form action="logincheck.jsp" name="form1" method="post">
       用户名:<input type="text" name="userName" size="18"><br>
       密    码:<input type="password" name="password" size="19"><br>
       验证码:<input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}"size="4">
      <%
      int intmethod1=(int)((((Math.random())*5))+1);
      int intmethod2=(int)((((Math.random())*5))+1);
      int intmethod3=(int)((((Math.random())*5))+1);
      int intmethod4=(int)((((Math.random())*5))+1);  
      String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4;
       %> 
       <input type="hidden" name="validationCode1" value="<%=intsum%>">
       <img style="height:20px;weight:20px" src="images/<%=intmethod1 %>.png">
       <img style="height:20px;weight:20px" src="images/<%=intmethod2 %>.png">
       <img style="height:20px;weight:20px" src="images/<%=intmethod3 %>.png">
       <img style="height:20px;weight:20px" src="images/<%=intmethod4 %>.png">
       <br>  
    <input type="submit" value="登录">
    <a href="register.jsp">注册</a>
    </form>
      </body>
    </html>
    

      

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@page import="com.gd.entity.Users"%>
    <%@page import="com.gd.entity.Msg"%>
    <%@page import="com.gd.dao.MsgDao"%>
    <%@page import="com.gd.dao.UsersDao"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        <title>登录</title>
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
      </head>
      <body>
      <%
      request.setCharacterEncoding("UTF-8");
    Users a=new Users();
    	String uname = request.getParameter("uname");
    	String upwd = request.getParameter("upwd");
    	String email = request.getParameter("uemail");
    	a.setUsername(uname);
    	a.setPassword(upwd);
    	a.setEmail(email);
    	UsersDao as=new UsersDao();
    	as.addUsers(a);
    	request.getRequestDispatcher("index.jsp").forward(request, response);
    %>
      </body>
    </html>
    

      

    <%@page import="com.gd.entity.Users"%>
    <%@page import="com.gd.dao.UsersDao"%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    	request.setCharacterEncoding(UTF-8");
    	String uname = request.getParameter("uname");
    	String upwd = request.getParameter("upwd");
    	UsersDao ud = new UsersDao();
    	if(request.getParameter("validationCode1").equals(request.getParameter("validationCode")))			
    {			
    	if (ud.login(uname, upwd)){		
    	//登录成功,创建User对象,并放入session
    		Users u=new Users();
    		u.setUsername(uname);
    		u.setPassword(upwd);
    		session.setAttribute("user", u);
    		request.getRequestDispatcher("main.jsp").forward(request, response);
    	}
    	else{
    		response.sendRedirect("index.jsp");
    		}
    	}
    		else{			
                    response.sendRedirect("index.jsp");			
                          }		
    %>
    

      

  • 相关阅读:
    第三天 moyax
    mkfs.ext3 option
    write file to stroage trigger kernel warning
    download fomat install rootfs script
    custom usb-seriel udev relus for compatible usb-seriel devices using kermit
    Wifi Troughput Test using iperf
    learning uboot switch to standby system using button
    learning uboot support web http function in qca4531 cpu
    learngin uboot design parameter recovery mechanism
    learning uboot auto switch to stanbdy system in qca4531 cpu
  • 原文地址:https://www.cnblogs.com/minmeishaonv/p/12919572.html
Copyright © 2020-2023  润新知