jsp第七周作业

custom.java
package com.gd.bean;

public class custom {

    
    public int getUid() {
        return uid;
    }
    public void setUid(int uid) {
        this.uid = uid;
    }
    public String getUname() {
        return uname;
    }
    public void setUname(String uname) {
        this.uname = uname;
    }
    public int getUpwd() {
        return upwd;
    }
    public void setUpwd(int upwd) {
        this.upwd = upwd;
    }
    private String uname;
    
    private int upwd;
    private int uid;
    public custom(int uid,int upwd,String uname){
        super();
        this.uid = uid;
        this.upwd = upwd;
        this.uname = uname;
    }
    
    

}


package com.gd.dao;


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

import com.gd.bean.custom;

customDao.java

public class customDao {

    java.sql.Connection con=null;
    java.sql.Statement sql;
    ResultSet rs;
    public void addCustom(custom s){
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "root");
            
            String sql="insert into save values(???)";
            PreparedStatement pw=con.prepareStatement(sql);
            pw.setInt(1, s.getUid());
            pw.setString(2, s.getUname());
            pw.setInt(3, s.getUpwd());
            pw.execute();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        
    }

}

login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>register</title>
<style type="text/css" ></style>
</head>
<body>
 
<form action="success1.jsp" method="post">
    编号:<input type="text" name="uid"><br>
    用户名:<input type="text" name="uname"><br>
    密   码:<input type="password" name="upwd"><br>
    
    <input type="submit" value="提交">
</form>
     
</body>
</html>
success1.jsp
<%@ page contentType="text/html" %>
<%@ page pageEncoding="utf-8" %>
<%@ page import="com.gd.bean.custom" %>
<%@ page language="java" import="com.gd.dao.customDao" %>
<%@ page language="java" import="java.util.*"%>

<html>
<body bgcolor=cyan>
<p style="font-family:黑体;font-size:36;color:bule">
<%        
        custom s=new custom();
        int id=Integer.paseInt(request.getParameter("uid"));
        s.setUid(id);
        String uname=request.getParameter("uname");
        s.setUname(uname);
        int upwd=Integer.paseInt(request.getParameter("upwd"));
        s.setUpwd(upwd);
        customDao ss=new customDao();
        ss.addcustom(s);
 %>
         编号: <%=id %><br/>
          用户名 : <%=uname %><br/>
            密码  : <%=upwd %>
</body>
</html>

posted @ 2021-04-17 21:22  white_poplar  阅读(57)  评论(0编辑  收藏  举报