石家庄铁道大学在校学生行程统计

一.题目要求
1、项目需求:
为了有效防止新冠疫情的传播,急需开发一套在校学生行程统计系统,完成信息统计,提前准备,有效保护在校学生的安全。
2.系统要求与功能设计
2.1 页面功能要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;
(2)网站页面整体风格统一;
(3)石家庄铁道大学在校学生行程统计页面,页面效果如图所示:

①页面详细信息如下表所示:

 

②点击“提交”按钮,保存成功则提示信息“填报成功”,失败则提示“信息填报错误”,并返回当前页面
2.2 功能要求
(1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种
(2)使用Serverlet实现信息提交功能
(3)使用Java Bean封装数据库连接操作

二.源代码

    package com.Bean

package com.Bean;
public class Userbean {
     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

package com.Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.Bean.Userbean;
import com.Util.Userutil;
public class Userdao {
     public void add(Userbean 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

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();
      }
  }
}

    add.jsp

<%@page import="com.Bean.Userbean"%>
<%@page import="com.Dao.Userdao"%>
<%@ 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
     {
        Userbean A = new Userbean();
        A.setName(name);
        A.setStudentid(studentid);
        A.setStudenttype(studenttype);
        A.setFaculty(faculty);
        A.setPhone(phone);
        A.setColor(color);
        A.setPath(path);
        A.setOther(other);
        Userdao Dao = new Userdao();
        Dao.add(A);
       
     }    
 %>
填报成功<br> 
 </html>

    jiemian.jsp

<%@ 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>
posted @ 2021-11-05 23:04  今天又双叒叕在敲代码  阅读(190)  评论(0编辑  收藏  举报