第十周作业

package com.a98.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BaseDao {
    public Connection getConnection() {
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return con;
    }
    
    protected void closeAll(Connection con,PreparedStatement ps,ResultSet rs){        
        try {
            if(rs != null)
                rs.close();
            if(ps != null)
                ps.close();
            if(con != null)
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

}



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>注册</title>
</head>
<body>
 
<form action="jump.jsp" method="post">
<table>
            <tr>
            <td>用户名</td>
            <td><input type="text" name="uname" /></td>
            </tr>
            <tr>
            <td>密码</td>
            <td><input type="text" name="upwd" /></td>
            </tr>
            <tr>
            <td>年龄</td>
            <td><input type="text" name="uage"/></td>
            </tr>
            <tr>
            <td><input type="submit" value="注册" /></td>
            <td><a href="login.jsp">登录</a></td>
            </tr>
            </table>
        </form>
</body>
</html>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>判断</title>
</head>
<body>
    <%
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
 
        StuDao s1 = new StuDao();
        if (s1.login(uname, upwd)) {
            request.getRequestDispatcher("true.jsp").forward(request, response);
        } else {
            request.getRequestDispatcher("false.jsp").forward(request, response);
        }
    %>
</body>
</html>



<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String name = request.getParameter("name");
    String passwords = request.getParameter("password");
    String ages = request.getParameter("age");


    int age = Integer.parseInt(ages);
    int password = Integer.parseInt(passwords);
    StuDao s1 = new StuDao();
    s1.reg(name, password, age);
    request.getRequestDispatcher("login.jsp").forward(request, response);
%>
</body>
</html>



<html>
 7 <head>
 8 <meta charset="utf-8">
 9 <title>My JSP 'index.jsp' starting page</title>
10 </head>
11 
12 <body>
13     <%
14         request.setCharacterEncoding("utf-8");
15         response.setCharacterEncoding("utf-8");
16         String uname = request.getParameter("uname");
17         String password = request.getParameter("password");
18         Integer age = Integer.parseInt(request.getParameter("age"));
19         User user = new User(uname, password, age);
20         UserDao userDao = new UserDao();
21         userDao.regUser(user);
22         response.sendRedirect("login.jsp");
23     %>
24 </body>
25 </html>


 

 

 

 

 

 

 

 
 
posted @ 2022-05-05 21:58  高杨翔  阅读(218)  评论(0)    收藏  举报