石家庄铁道大学在校学生行程统计(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日以来到过湖南长沙;青海海东市

(以上选项可以多选)

其他涉疫信息需要填报的

文本框

 

 

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

评分标准:

①完成石家庄铁道大学在校学生行程统计页面(未完成0分,完成2分);

②保存行程信息入库(未完成0分,完成6分);

③学号和联系电话判断是否为指定位数的数字。(未完成0分,完成一个0.5,全部完成1分);

④学生类别和健康码颜色实现单选框选择功能(未完成0分,完成一个0.5,全部完成1分);

⑤实现院系下拉框功能(未完成0分,完成1分)。

⑥实现行程统计复选框功能(未完成0分,完成2分)

⑦实现提交后信息提示功能;(未完成0分,完成2分)

2.2 功能要求

1)设计出合理的数据库和数据表,要求使用mysql、sqlserver、oracle三种数据库中一种(1分)

2)使用Serverlet实现信息提交功能(1分)。

3)使用Java Bean封装数据库连接操作(2分。)

 

项目结构

 

 

数据库

 

 

bean.jsp

package Bean;

public class bean
{
String name;
String id;
String leibie;
String yuanxi;
String tel;
String mcolor;
String xc;
String other;

public String getName()
{
return name;
}

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

public String getId()
{
return id;
}

public void setId(String id)
{
this.id = id;
}

public String getLeibie()
{
return leibie;
}

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

public String getYuanxi()
{
return yuanxi;
}

public void setYuanxi(String yuanxi)
{
this.yuanxi = yuanxi;
}

public String getTel()
{
return tel;
}

public void setTel(String tel)
{
this.tel = tel;
}

public String getMcolor()
{
return mcolor;
}

public void setMcolor(String mcolor)
{
this.mcolor = mcolor;
}

public String getXc()
{
return xc;
}

public void setXc(String xc)
{
this.xc = xc;
}

public String getOther()
{
return other;
}

public void setOther(String other)
{
this.other = other;
}
}

dao.jsp

package Dao;

import Bean.bean;
import Util.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class dao

{
public int add(bean bean) throws ClassNotFoundException, SQLException
{
//获得链接对象
Connection connection = util.getConnection();
//准备sql语句
String sql = "insert into xctj(姓名, 学号, 学生类别, 院系, 联系电话, 健康码颜色, 行程统计, 其他信息) values(?,?,?,?,?,?,?,?)";
PreparedStatement preparedStatement = null;
try {
//创建语句传输对象
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, bean.getName());
preparedStatement.setString(2, bean.getId());
preparedStatement.setString(3, bean.getLeibie());
preparedStatement.setString(4, bean.getYuanxi());
preparedStatement.setString(5, bean.getTel());
preparedStatement.setString(6, bean.getMcolor());
preparedStatement.setString(7, bean.getXc());
preparedStatement.setString(8, bean.getOther());
preparedStatement.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//关闭资源

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

return 1;
}
}

util.jsp

 

package 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;


/**
* @author mendianyu
*/
public class util {
public static Connection getConnection() throws ClassNotFoundException, SQLException {
//连接数据库
Connection connection = null;
//Statement 对象用于将 SQL 语句发送到数据库中。
Statement stmt = null;
ResultSet rs = null;
//1. 导入驱动jar包
//2.注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1 ?useUnicode=true&characterEncoding=utf8", "root", "Mendy030628");

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 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="add_back.jsp" method="get">
<p style="text-align: center">
信息登记
<br>
姓名
<label>
<input type="text" name="name" />
</label>
<br>
学号
<label>
<input type="text" name="id" maxlength="8" oninput="this.value = this.value.replace(/[^0-9]/g, '');"/>
</label>
<br>
学生类别
<label>
<input type="radio" name="leibie" value="本科生">本科生
<input type="radio" name="leibie" value="研究生" checked>研究生
</label>
<br>
院系
<select name="yuanxi">
<option value="土木学院">土木学院</option>
<option value="机械学院">机械学院</option>
<option value="交通学院">交通学院</option>
<option value="信息学院" selected>信息学院</option>
<option value="经管学院">经管学院</option>
</select>
<br>
联系电话
<label>
<input type="text" name="tel" maxlength="11"oninput="this.value = this.value.replace(/[^0-9]/g, '');"/>
</label>
<br>
健康码颜色
<label>
<input type="radio" name="mcolor" value="绿码"checked>绿码
<input type="radio" name="mcolor" value="黄码" >黄码
<input type="radio" name="mcolor" value="红码">红码
</label>
<br>
行程统计

<input type="checkbox" name="xc" value="去过北京">去过北京
<input type="checkbox" name="xc" value="去过上海">去过上海
<input type="checkbox" name="xc" value="去过广州">去过广州
<input type="checkbox" name="xc" value="去过杭州">去过杭州

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

<br>
<input type="submit" value="提交" />
<input type="reset" value="重置" />
<br>
<input type="button" value="返回主菜单" onclick="location.href='menu.jsp'">
</p>
</form>
</body>

add_back.jsp
<%@ page import="java.sql.SQLException" %>
<%@ page import="Bean.bean" %>
<%@ page import="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>
<meta charset="UTF-8">

<%
// request.setCharacterEncoding("UTF8");//加上这句,否则数据库的表中文为乱码

String name = request.getParameter("name");
String id = request.getParameter("id");
String leibie = request.getParameter("leibie");
String yuanxi = request.getParameter("yuanxi");
String tel = request.getParameter("tel");
String mcolor = request.getParameter("mcolor");
String xc = request.getParameter("xc");
String other = request.getParameter("other");


if(id=="")
{
out.print("<script language='javaScript'> alert('学号输入为空'); window.history.back(-1); </script>");
}
else if(id.length()!=8)
{
out.print("<script language='javaScript'> alert('学号位数不是8位,请检查并更改'); window.history.back(-1); </script>");
}
else if(name=="")
{
out.print("<script language='javaScript'> alert('姓名输入为空'); window.history.back(-1); </script>");
}
else if(tel=="")
{
out.print("<script language='javaScript'> alert('电话输入为空'); window.history.back(-1); </script>");
}
else if (tel.length()!=11)
{
out.print("<script language='javaScript'> alert('电话号码不是11位,请检查并更改'); window.history.back(-1); </script>");
}
else if(other=="")
{
out.print("<script language='javaScript'> alert('其他信息为空,若没有请填无'); window.history.back(-1); </script>");
}

else
{

bean bean = new bean();
bean.setName(name);
bean.setId(id);
bean.setLeibie(leibie);
bean.setYuanxi(yuanxi);
bean.setTel(tel);
bean.setMcolor(mcolor);
bean.setXc(xc);
bean.setOther(other);

dao dao = new dao();
try
{
dao.add(bean);
} catch (ClassNotFoundException | SQLException e)
{
e.printStackTrace();
}
out.print("<script language='javaScript'> alert('添加成功');</script>");

}
%>
</html>

 

仍存在的问题:多选只能录进去一个数据

原文地址:http://www.cnblogs.com/mendianyu/p/16826372.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性