疫情到往记录

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>石家庄铁道大学在校学生信息行程信息统计</title>
</head>
<body>
<form action="add.jsp" method="get">
    <table align="center" border="1" width="500">

        <tr>
            <td>姓名 : </td>
            <td>
                <input type="text" name="name" />
            </td>
        </tr>

        <tr>
            <td>学号:</td>
            <td>
                <input type="tel" name="studentid" required pattern="[0-9]{8}"/>
            </td>
        </tr>

        <tr>
            <td>学生类型:</td>
            <td>
                <input type="radio" name="studenttype" value="本科生" >本科生
                <input type="radio" name="studenttype" value="研究生" >研究生
            </td>
        </tr>

        <tr>
            <td>院系:</td>
            <td>
                <select name="college">
                    <option value="土木学院">土木学院</option>
                    <option value="机械学院">机械学院</option>
                    <option value="交通学院">交通学院</option>
                    <option value="信息学院">信息学院</option>
                    <option value="经管学院">经管学院</option>
                </select>
            </td>
        </tr>

        <tr>
            <td>联系电话:</td>
            <td>
                <input type="tel" name="phone" required pattern="[0-9]{11}"/>
            </td>
        </tr>

        <tr>
            <td>行程统计:</td>
            <td>
                <input type="checkbox" name="path" value="10月30日去过人民医院">10月30日去过人民医院<br>
                <input type="checkbox" name="path" value="10月25日以来去过深泽县人民医院">10月25日以来去过深泽县人民医院<br>
                <input type="checkbox" name="path" value="10月16日以来去过深泽县庄泽村">10月16日以来去过深泽县庄泽村<br>
                <input type="checkbox" name="path" value="10月29日以来去过黑龙江哈尔滨市或者黑河市">10月29日以来去过黑龙江哈尔滨市或者黑河市<br>
                <input type="checkbox" name="path" value="10月18日以来途径贵州遵义市;北京丰台、昌平">10月18日以来途径贵州遵义市;北京丰台、昌平<br>
                <input type="checkbox" name="path" value="10月17日以来到过湖南长沙;青海海东市">10月17日以来到过湖南长沙;青海海东市<br>
            </td>
        </tr>

        <tr>
            <td>健康码颜色:</td>
            <td>
                <input type="radio" name="color" value="绿码" >绿码
                <input type="radio" name="color" value="黄码" >黄码
                <input type="radio" name="color" value="红码" >红码
            </td>
        </tr>

        <tr>
            <td>其他涉疫信息需要填报的:</td>
            <td>
                <input type="text" name="other" />
            </td>
        </tr>

        <tr align="center">
            <td colspan="2">
                <input type="submit" value="提交">
            </td>
        </tr>
    </table>
</form>
</body>
</html>

以上是screen界面的html代码。

<%@page import="com.Bean.Bean"%>
<%@page import="com.dao.dao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
  //接收客户端传递过来的参数
  String name = request.getParameter("name");
  String studentid = request.getParameter("studentid");
  String studenttype = request.getParameter("studenttype");
  String faculty = request.getParameter("faculty");
  String phone = request.getParameter("phone");
  String color = request.getParameter("color");
  String path = request.getParameter("path");
  String other = request.getParameter("other");
  // try{
  //if()
  {
    // throw new ClassException("信息填报错误");
  }
  //  else if()
  {
    // throw new ClassException("信息填报错误");
  }
  // else
  {
    Bean A = new Bean();
    A.setName(name);
    A.setStudentid(studentid);
    A.setStudenttype(studenttype);
    A.setFaculty(faculty);
    A.setPhone(phone);
    A.setColor(color);
    A.setPath(path);
    A.setOther(other);
    dao Dao = new dao();
    Dao.add(A);

  }
%>
填报成功<br>
</html>
package com.Bean;
public class Bean {
    private String  name;
    private String  studentid;
    private String  studenttype;
    private String  faculty;
    private String  phone;
    private String  color;
    private String  path;
    private String  other;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name= name;
    }

    public String getStudentid() {
        return studentid;
    }
    public void setStudentid(String studentid) {
        this.studentid = studentid;
    }

    public String getStudenttype() {
        return studenttype;
    }
    public void setStudenttype(String studenttype) {
        this.studenttype = studenttype;
    }

    public String getFaculty() {
        return faculty;     }
    public void setFaculty(String faculty) {
        this.faculty = faculty;
    }

    public String getPhone() {
        return phone;     }
    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getColor() {
        return color;     }
    public void setColor(String color) {
        this.color = color;
    }

    public String getPath() {
        return path;     }
    public void setPath(String path) {
        this.path = path;
    }

    public String getOther() {
        return other;     }
    public void setOther(String other) {
        this.other = other;
    }
}
package com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.Bean.Bean;
import com.Util.userUtil;
public class dao {
    public void add(Bean claz) throws ClassNotFoundException, SQLException
    {
        //获得链接对象
        Connection connection = userUtil.getConnection();
        //准备sql语句
        String sql = "insert into course(name,studentid,studenttype,faculty,phone,color,path,other) values(?,?,?,?,?,?,?,?)";
        PreparedStatement preparedStatement = null;
        try {
            //创建语句传输对象
            preparedStatement = connection.prepareStatement(sql);
            // preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, claz.getName());
            preparedStatement.setString(2, claz.getStudentid());
            preparedStatement.setString(3, claz.getStudenttype());
            preparedStatement.setString(4, claz.getFaculty());
            preparedStatement.setString(5, claz.getPhone());
            preparedStatement.setString(6, claz.getColor());
            preparedStatement.setString(7, claz.getPath());
            preparedStatement.setString(8, claz.getOther());
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            //关闭资源

            //DBUtil.close(preparedStatement);
            //DBUtil.close(connection);
        }

    }
}
package com.Util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class userUtil {
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Connection connection = null;//连接数据库
        Statement stmt = null;//Statement 对象用于将 SQL 语句发送到数据库中。
        ResultSet rs = null;
        //1. 导入驱动jar包
        //2.注册驱
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/qz", "root", "mysqlmima");

        return connection;
    }

    public static void close(Connection connection ) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close(PreparedStatement preparedStatement ) {
        try {
            if (preparedStatement != null) {
                preparedStatement.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void close(ResultSet resultSet ) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

 

posted @ 2022-10-16 14:02  YE-  阅读(54)  评论(0编辑  收藏  举报