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

作业要求:

石家庄铁道大学在校学生行程统计(20分)

考试时间:180分钟

1、项目需求:

为了有效防止新冠疫情的传播,急需开发一套在校学生行程统计系统,完成信息统计,提前准备,有效保护在校学生的安全。

2.系统要求与功能设计

2.1 页面功能要求

1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)

2)网站页面整体风格统一;

3)石家庄铁道大学在校学生行程统计页面,页面效果如图所示:(15分)

 

  

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

信息标题

信息类型

填写要求

姓名

文本框

 

学号

文本框

要求输入八位数字

学生类别

单选框

单选项:本科生或者研究生

院系

下拉列表框

下来列表框内容包括(土木学院、机械学院、交通学院、信息学院、经管学院)

联系电话

文本框

要求输入11位数字

健康码颜色

单选框

单选选项(绿码、黄码、红码)

行程统计

复选框

□10月30日去过人民医院

□10月25日以来去过深泽县人民医院

□10月16日以来去过深泽县庄泽村

□10月29日以来去过黑龙江哈尔滨市或者黑河市

□10月18日以来途径贵州遵义市;北京丰台、昌平

□10月17日以来到过湖南长沙;青海海东市

(以上选项可以多选)

其他涉疫信息需要填报的

文本框

 

 

点击“提交”按钮,保存成功则提示信息“填报成功”,失败则提示“信息填报错误”,并返回当前页面

 

 五个文件

Bean1.java

package com.Bean;

public class  Bean1
{

        private String  name;//姓名
        private String  id;//学号
        private String  leibie;//学生类别
        private String  xueyuan;//院系
        private String  phone;//联系电话
        private String  color;//健康码颜色
        private String  xingcheng;//行程统计
        private String  qita;//其他信息


        public String getName() {
                return name;
        }
        public void setName(String name) {
                this. name =  name;
        }
        public String getId() {
                return String.valueOf(id);
        }
        public void setId(String id) {
                this.id = id;
        }
        public String getLeibie() {

                return leibie;     }
        public void setLeibie(String leibie) {
                this.leibie = leibie;
        }
        public String getXueyuan() {

                return xueyuan;
        }
        public void setXueyuan(String xueyuan) {
                this.xueyuan = xueyuan;
        }
        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 getXingcheng() {
                return xingcheng;
        }

        public void setXingcheng(String xingcheng) {
                this.xingcheng = xingcheng;
        }

        public String getQita() {
                return qita;
        }

        public void setQita(String qita) {
                this.qita = qita;
        }

Dao1.java

package com.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.Bean.Bean1;
import com.Util.Util1;


public class Dao1 {

    public int add(Bean1 claz) throws ClassNotFoundException, SQLException
    {
        //获得链接对象
        Connection connection = Util1.getConnection();
        //准备sql语句
        String sql = "insert into biao1(name,id,leibie,xueyuan,phone,color,xingcheng,qita) values(?,?,?,?,?,?,?,?)";
        PreparedStatement preparedStatement = null;
        try {
            //创建语句传输对象
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, claz.getName());
            preparedStatement.setString(2, claz.getId());
            preparedStatement.setString(3, claz.getLeibie());
            preparedStatement.setString(4, claz.getXueyuan());
            preparedStatement.setString(5, claz.getPhone());
            preparedStatement.setString(6, claz.getColor());
            preparedStatement.setString(7, claz.getXingcheng());
            preparedStatement.setString(8, claz.getQita());
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            //关闭资源

            Util1.close(preparedStatement);
            Util1.close(connection);
        }

        return 1;
    }

}

Util1.java

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 Util1 {
    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.cj.jdbc.Driver");
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/xingcheng ?useUnicode=true&characterEncoding=utf8", "root", "123456");

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

back.jsp

<%--
  Created by IntelliJ IDEA.
  User: 榕宝
  Date: 2021/11/5
  Time: 14:32
  To change this template use File | Settings | File Templates.
--%>
<%@page import="com.Bean.Bean1"%>
<%@page import="com.Dao.Dao1"%>
<%@ page import="java.sql.SQLException" %>
<%@ 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>
<meta charset="UTF-8">

<%
    
    int i=0;
String name = request.getParameter("name");
String id = request.getParameter("id");
String leibie = request.getParameter("leibie");
String xueyuan = request.getParameter("xueyuan");
String phone = request.getParameter("phone");
String color = request.getParameter("color");
//String xingcheng = request.getParameter("xingcheng");
String qita = request.getParameter("qita");
    String a1=null;
    String a2=null;
    String a3=null;
    String a4=null;
    String a5=null;
    String a6=null;
    if(request.getParameter("a1")!=null)
    {
        a1=request.getParameter("a1")+' ';
    }
    else a1=" ";
    if(request.getParameter("a2")!=null)
    {
        a2=request.getParameter("a2")+' ';
    }
    else a2=" ";
    if(request.getParameter("a3")!=null)
    {
        a3=request.getParameter("a3")+' ';
    }
    else a3=" ";
    if(request.getParameter("a4")!=null)
    {
        a4=request.getParameter("a4")+' ';
    }
    else a4=" ";
    if(request.getParameter("a5")!=null)
    {
        a5=request.getParameter("a5")+' ';
    }
    else a5=" ";
    if(request.getParameter("a6")!=null)
    {
        a6=request.getParameter("a6")+' ';
    }
    else a6=" ";
    String xingcheng=a1+a2+a3+a4+a5+a6;

Bean1 bean = new Bean1();
bean.setName(name);
bean.setId(id);
bean.setLeibie(leibie);
bean.setXueyuan(xueyuan);
bean.setPhone(phone);
bean.setColor(color);
bean.setXingcheng(xingcheng);
bean.setQita(qita);
Dao1 dao =new Dao1();
    try {
        i=dao.add(bean);
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }
    if(i==1)
        response.getWriter().append("填报成功!");
    else
        response.getWriter().append("信息填报错误!");
       response.sendRedirect("screen.jsp");

%>
</html>
<%!

%>

screen.jsp

<%--
  Created by IntelliJ IDEA.
  User: 榕宝
  Date: 2021/11/5
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ 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">
<head>
    <meta charset="UTF-8" >
    <title>石家庄铁道大学在校学生行程统计</title>
</head>

<body>
    <form action="back.jsp" method="post">
        <table align="center" border="1" width="500">
            <tr>
                <td>1.姓名: </td>
                <td>
                    <label>
                        <input type="text" name="name" />
                    </label>
                </td>
            </tr>
            <tr>
                <td>2.学号 </td>
                <td>
                    <label>
                        <input type="text" name="id" maxlength="8"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>3.学生类别: </td>
                <td>
                    <label>
                        <input type="radio" name="leibie" value="本科生">本科生
                        <input type="radio" name="leibie" value="研究生" checked>研究生
                    </label>
                </td>
            </tr>
            <tr>
                <td>4.院系:</td>
                <td>
                    <label>
                        <select name="xueyuan">
                            <option value="土木学院">土木学院</option>
                            <option value="机械学院">机械学院</option>
                            <option value="交通学院">交通学院</option>
                            <option value="信息学院" selected>信息学院</option>
                            <option value="经管学院">经管学院</option>
                        </select>
                    </label>
                </td>
            </tr>
            <tr>
                <td>5.联系电话: </td>
                <td>
                    <label>
                        <input type="text" name="phone" maxlength="11"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>6.健康码颜色: </td>
                <td>
                    <label>
                        <input type="radio" name="color" value="绿码">绿码
                        <input type="radio" name="color" value="黄码" checked>黄码
                        <input type="radio" name="color" value="红码">红码
                    </label>
                </td>
            </tr>
            <tr>
                <td>7.行程统计: </td>
                <td>
                    <label>
                        <input type="checkbox" name="xingcheng"  value="10月30日去过人民医院" />10月30日去过人民医院
                        <input type="checkbox" name="xingcheng"  value="10月25日以来去过深泽县人民医院" />10月25日以来去过深泽县人民医院
                        <input type="checkbox" name="xingcheng"  value="10月16日以来去过深泽县庄泽村" />10月16日以来去过深泽县庄泽村
                        <input type="checkbox" name="xingcheng"  value="10月29日以来去过黑龙江哈尔滨市或者黑河市" />10月29日以来去过黑龙江哈尔滨市或者黑河市
                        <input type="checkbox" name="xingcheng"  value="10月18日以来途径贵州遵义市;北京丰台、昌平" />10月18日以来途径贵州遵义市;北京丰台、昌平
                        <input type="checkbox" name="xingcheng" value="10月17日以来到过湖南长沙;青海海东市" checked="checked"/>10月17日以来到过湖南长沙;青海海东市
                    </label>
                </td>
            </tr>
            <tr>
                <td>8.其他涉疫信息需要填报的 </td>
                <td>
                    <label>
                        <input type="text" name="qita" />
                    </label>
                </td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <input type="submit" value="提交" />
                    <input type="reset" value="重置" />
                </td>
            </tr>
        </table>
    </form>
</body>

显示界面

 

 后续还需要改进,关于遇到的问题写在下一篇博客

posted @ 2021-11-05 22:35  zrswheart  阅读(517)  评论(0编辑  收藏  举报