jsp第八次作业

数据库test 中建个表 stu(stuid 主键 自动增长 ,用户名,密码,年龄)

1.设计一个注册页面,实现用户注册功能
2.设计一个登陆页面,实现用户名密码登陆
3.两个页面可以互相超链接

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>

<body>
<script type="text/javascript">
        function validate(){
            if(loginForm.uname.value==""){
                alert("账号不能为空!");
                return;
            }
            if(loginForm.upwd.value==""){
                alert("密码不能为空!");
                return;
            }
            loginForm.submit();
        }
    </script>


    <form name="loginForm" action="dologin.jsp" method="post">
        
    用户名:<input type="text" name="uname" ><br> 
    密码: <input  type="password" name="upwd"  >
    
        <input type="button" value="登录" onClick="validate()">    
        <a href="zhuce.jsp">注册</a>


    </form>

</body>
</html>

  

<%@page import="com.cby.StuDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title></title>
</head>

<body>
<%
    StuDao sd=new StuDao();
    request.setCharacterEncoding("utf-8");
    String uname = request.getParameter("uname");
    String upwd = request.getParameter("upwd");
    if (sd.login(uname, upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request, response);
    }else{
        out.print("登陆失败,即将跳回登陆页.....");
        response.setHeader("refresh", "3;url=login.jsp");
    }

 %>

</body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
        function validate(){
            if(loginForm.stuid.value==""){
                alert("id不能为空!");
                return;
            }
            if(loginForm.uname.value==""){
                alert("账号不能为空!");
                return;
            }
            if(loginForm.upwd.value==""){
                alert("密码不能为空!");
                return;
            }
            if(loginForm.upwd1.value==""){
                alert("确认密码不能为空!");
                return;
            }
            if(loginForm.uage.value==""){
                alert("年龄不能为空!");
                return;
            }
            loginForm.submit();
        }
    </script>

    <form name="loginForm" action="dozhuce.jsp" method="post">
    学生id:<input type="number" name="stuid" ><br> 
    用户名:<input type="text" name="uname" ><br> 
    密码: <input  type="password" name="upwd"  ><br> 
    确认密码: <input  type="password" name="upwd1" ><br> 
    年龄:<input type="number" name="uage" ><br> 
    <a href="login.jsp">返回登录</a>
        <input type="button" value="注册" onClick="validate()">    
    </form>


</body>
</html>

  

<%@page import="com.cby.StuDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>

<body>
<%
    
    request.setCharacterEncoding("utf-8");
    
    String id =request.getParameter("stuid");
    Integer stuid =Integer.parseInt(id);
    
    String uname = request.getParameter("uname");
    
    String upwd = request.getParameter("upwd");
    
    String upwd1 = request.getParameter("upwd1");
    
    String age =request.getParameter("uage");
    Integer uage =Integer.parseInt(age);
    
        if((upwd.equals(upwd1))){
            StuDao sd=new StuDao();
            sd.reg(stuid, uname, upwd, uage);
            out.print("注册成功,即将跳回登录页.....");
            response.setHeader("refresh", "3;url=login.jsp");
    }
    else{
        out.print("两次密码不一致,即将跳回注册页.....");
            response.setHeader("refresh", "3;url=zhuce.jsp");
    }
        
    
    
 %>
</body>
</html>

  

<%@page import="com.cby.StuDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title></title>
</head>

<body>
<%
    StuDao sd=new StuDao();
    request.setCharacterEncoding("utf-8");
    String uname = request.getParameter("uname");
    String upwd = request.getParameter("upwd");
    if (sd.login(uname, upwd)){
        session.setAttribute("uname", uname);
        request.getRequestDispatcher("main.jsp").forward(request, response);
    }else{
        out.print("登陆失败,即将跳回登陆页.....");
        response.setHeader("refresh", "3;url=login.jsp");
    }


 %>



</body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>My JSP 'index.jsp' starting page</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>
    This is my JSP page. <br>
  </body>
</html>

  

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
登录成功
</body>
</html>
复制代码

  

 

 

 

posted @ 2022-05-08 20:32  愿你与世界温柔相拥  阅读(26)  评论(0编辑  收藏  举报