JSP/JAVAWEB/SSM/J2EE高考志愿填报推荐系统的开发
目录
1、概述
开发环境: jdk1.8、tomcat7.0 、mysql5.2
开发工具:idea2019.3.1、navicat15
编程语言后端:java;框架和引用的包:JavaBean Servlet MVC、log4j.jar
编程语言前端:JSP、html5、javascript、jquery;框架和引用的包:My97DatePicker、ueditor
注:本项目未引用当前流行的ssm(Spring+SpringMVC+MyBatis)、Spring boot,在随后的项目中讲解
2、功能描述
根据需求阶段的所得结论,将系统对数据的处理以数据流程图的形式体现出来,结合系统自身的特点以及开发任务的分配方式,设计出整个系统的大致功能模块的结构。
高考志愿填报参考系统是一个典型的数据库应用程序,由前台用户和后台管理员模块组成,规划如下:
前台登录模块
用户进入网站后可以注册成为网站会员,然后输入自己的用户名和密码登录网站。
前台注册模块
用户进入网站后可以输入相关信息注册成为网站会员。
前台新闻动态
用户登录系统后可以查看网站新闻信息。
前台资料下载
用户登录后可以下载网站的相关资料信息。
前台修改密码
学生登录系统后可以修改自己的密码信息和个人信息
前台志愿意向推荐
学生登录系统后可以查看历史录取信息列表,如年份、学校、专业、分类等。
后台用户管理模块
管理员登录系统后可以添加、编辑、删除、搜索用户信息,如用户名称、真实姓名、性别等。
后台学校管理模块
管理员登录系统后可以添加、编辑、删除学校信息,如学校名称、类型、城市等。
后台学生信息模块
管理员登录系统后可以添加、编辑删除学生信息,如用户、真实姓名、性别、所报院校城市、爱好、家庭情况等;
后台历年录取分数线信息模块
管理员登录系统后可以搜索、新增、编辑、删除历年录取分数线信息,如年份、学校等;
后台新闻类型模块
该模块的主要功能是实现对网站新闻类型的编辑、删除等, 如名称。
后台公告管理模块
该模块的主要功能是实现对网站公告信息的搜索、查看、编辑、删除等,如果标题、日期、分类等。
3、数据表
1 | admin | 管理员表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
username | varchar | 用户名 |
password | varchar | 密码 |
creattime | datetime | 日期 |
flag | int | 状态 |
isuse | int | 是否使用 |
logintimes | int | 登录次数 |
quanxian | varchar | 权限 |
2 | adminlog | 登录日志表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
username | varchar | 用户名 |
password | varchar | 密码 |
logintime | datetime | 日期 |
loginip | varchar | IP |
4 | Bulletin | 公告表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
title | varchar | 标题 |
content | varchar | 内容 |
userId | int | 用户名 |
createTime | varchar | 日期 |
5 | prof | 专业表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
name | varchar | 名称 |
6 | pstu | 学生详细信息 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
mid | int | 学生ID |
realname | varchar | 姓名 |
sex | varchar | 性别 |
bir | varchar | 出生日期 |
sheng | varchar | 学籍所在地 |
city | varchar | |
telphone | varchar | 电话 |
varchar | 邮件 | |
question | varchar | 密码问题 |
answer | varchar | 密码答案 |
code | varchar | 准考证号 |
address | varchar | 地址 |
syadd | varchar | 生源地 |
school | varchar | 所在学校 |
7 | school | 学校表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
city | varchar | 省份 |
shcool | varchar | 学校名称 |
8 | stu | 学生表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
username | varchar | 用户名 |
password | varchar | 密码 |
regtime | datetime | 注册日期 |
ifuse | int | 是否使用 |
logintimes | int | 登录次数 |
lasttime | datetime | 最后登录时间 |
lastip | varchar | 登录IP |
9 | wish | 志愿表 |
字段名称 | 字段类型 | 说明 |
id | int | 编号 |
dsname | varchar | 联系人姓名 |
prof | varchar | 专业 |
stime | datetime | 开始报名日期 |
etime | datetime | 录取结束日期 |
school | varchar | 学校名称 |
num | int | 招生名额 |
kaoshi | int | 分数线 |
4、目录结构
5、实现过程
5.1 SRC目录
action层: :Servlet Model 与 View 之间沟通的桥梁,它可以分派用户的请求并选择恰当的视图以用于显示,同时它也可以解释用户的输入并将它们映射为模型层可执行的操作,当然就是 Servlet 的职责了。
以公告模块为例
// Source File Name: BulletinServlet.java
package com.action;
import com.bean.BulletinBean;
import com.sun.net.ssl.internal.ssl.Debug;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class BulletinServlet extends HttpServlet
{
public BulletinServlet()
{
}
public void destroy()
{
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
HttpSession session = request.getSession();
String method = request.getParameter("method");
//System.out.println(method);
BulletinBean Bulletin = new BulletinBean();
if (method.equals("addBulletin"))
{
String title = request.getParameter("title");
String content = request.getParameter("content");
Debug.println(title, content);
int flag = Bulletin.addBulletin(title,content);
if (flag == 1)
{
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
} else
{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
}
} else
if (method.equals("delBulletin"))
{
String id = request.getParameter("id");
int flag = Bulletin.delBulletin(id);
if (flag == 1)
{
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
} else
{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
}
} else
if (method.equals("upBulletin"))
{
int id = Integer.parseInt(request.getParameter("id"));
String title = request.getParameter("title");
String content = request.getParameter("content");
int flag = Bulletin.upBulletin(title,content,id);
if (flag == 1)
{
request.setAttribute("message", "操作成功!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
} else
{
request.setAttribute("message", "操作失败!");
request.getRequestDispatcher("admin/bulletin/index.jsp").forward(request, response);
}
}
}
public void init()
throws ServletException
{
}
}
bean层: 实现系统的业务逻辑与数据库交互
以公告模块为例
package com.bean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.util.Constant;
import com.util.DBO;
public class BulletinBean {
private List list;
private ResultSet rs;
private int EVERYPAGENUM = 2;
private int count = -1;
private int qq = 0;
private String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
//分页查询
public void setEVERYPAGENUM(int EVERYPAGENUM){
this.EVERYPAGENUM=EVERYPAGENUM;
}
public int getMessageCount() { //得到信息总数
String sql="select count(*) from Bulletin";
DBO dbo=new DBO();
dbo.open();
try {
rs = dbo.executeQuery(sql);
rs.next();
count = rs.getInt(1);
return count;
} catch (SQLException ex) {
ex.printStackTrace();
return -1;
} finally {
dbo.close();
}
}
public int getPageCount() { //得到共多少页(根据每页要显示几条信息)
if (count % EVERYPAGENUM == 0) {
return count / EVERYPAGENUM;
} else {
return count / EVERYPAGENUM + 1;
}
}
public List getBulletin(int page){
String sql="select * from Bulletin order by id desc";
DBO dbo = new DBO();
dbo.open();
list =new ArrayList();
try{
rs=dbo.executeQuery(sql);
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
qq++;
List list2=new ArrayList();
list2.add(rs.getString("id"));
list2.add(rs.getString("title"));
list2.add(rs.getString("content"));
list2.add(rs.getString("userid"));
list2.add(rs.getString("createtime"));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
} finally {
dbo.close();
}
}
//前台显示公告内容
public List getShow(String id){
String sql="select * from Bulletin where id='"+id+"'";
DBO dbo = new DBO();
dbo.open();
List list2 =new ArrayList();
try{
rs=dbo.executeQuery(sql);
while(rs.next()){
list2.add(rs.getString("id"));
list2.add(rs.getString("title"));
list2.add(rs.getString("content"));
list2.add(rs.getString("userid"));
list2.add(rs.getString("createtime"));
}
return list2;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
public int addBulletin(String title,String content){
String sql="insert into Bulletin(title,content,userid,createtime) values('"+title+"','"+content+"','1','"+date+"')";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public int delBulletin(String id){
String sql="delete from Bulletin where id='"+id+"'";
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
public int upBulletin(String title,String content,int id){
String sql="update Bulletin set title='"+title+"'"+" , content='"+content+"'"+" , createtime='"+date+"'"+" where id="+id;
DBO dbo = new DBO();
dbo.open();
try{
int i = dbo.executeUpdate(sql);
if(i == 1)
return Constant.SUCCESS;
else
return Constant.SYSTEM_ERROR;
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
}
util 一些常用到的公用方法 数据库连接代码 MD5密码加密等
md5加密代码
/* */ package com.util;
/* */
/* */ import java.security.MessageDigest;
/* */
/* */ public final class MD5
/* */ {
/* */ public static final String MD5(String s)
/* */ {
/* 13 */ char[] hexDigits = {
/* 14 */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
/* 15 */ 'e', 'f' };
/* */ try {
/* 17 */ byte[] strTemp = s.getBytes();
/* 18 */ MessageDigest mdTemp = MessageDigest.getInstance("MD5");
/* 19 */ mdTemp.update(strTemp);
/* 20 */ byte[] md = mdTemp.digest();
/* 21 */ int j = md.length;
/* 22 */ char[] str = new char[j * 2];
/* 23 */ int k = 0;
/* 24 */ for (int i = 0; i < j; ++i) {
/* 25 */ byte byte0 = md[i];
/* 26 */ str[(k++)] = hexDigits[(byte0 >>> 4 & 0xF)];
/* 27 */ str[(k++)] = hexDigits[(byte0 & 0xF)];
/* */ }
/* 29 */ return new String(str);
/* */ } catch (Exception e) {
/* */ }
/* 32 */ return null;
/* */ }
/* */ }
/* Location:
* Qualified Name: com.util.MD5
* JD-Core Version: 0.5.3
*/
5.2 webroot前端文件
View层:负责与用户交互,即在界面上展示数据对象给用户,即html,jsp
Fckeditor 目录 ,多媒体编辑框,用在新闻编辑和添加的时候,输入文字样式的修改,类似于word的编辑功能
效果
公告显示页面代码
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312" %>
<jsp:useBean id="sys" scope="page" class="com.bean.SystemBean" />
<jsp:useBean id="hk" scope="page" class="com.bean.HkBean"/>
<jsp:useBean id="Common" scope="page" class="com.util.Common"/>
<jsp:useBean id="Validate" scope="page" class="com.util.Validate" />
<jsp:useBean id="bulletin" scope="page" class="com.bean.BulletinBean"></jsp:useBean>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>招生简章</title>
<link href="stylesheet/style.css" rel="stylesheet" type="text/css" />
</head>
<body onload="times()">
<div id="container">
<jsp:include page="head.jsp"/>
<div class="banner"><img src="images/banner.jpg" alt="" width="950" height="198" /></div>
<!--中部内容-->
<div class="clear"></div>
<div class="workzone">
<!--中部左侧-->
<jsp:include page="left.jsp"/>
<!--中部左侧结束-->
<!--中部右侧开始-->
<div class="workzone-right">
<%
String id=request.getParameter("id");
List list=bulletin.getShow(id);
%>
<div align="center" style="font-size:20px"><strong><%=list.get(1).toString() %></strong> </div>
<div style="padding:20px;" align="left">
<%=list.get(2).toString() %>
<br>
<br>
</div>
<div class="clear"></div>
<!-- /pages -->
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<jsp:include page="footer.jsp"/>
</body>
</html>
WEB-INF目录里的\ web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_1511523771762" version="2.4">
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>enabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFile</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFile</param-name>
<param-value>
php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi
</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsImage</param-name>
<param-value>jpg|gif|jpeg|png|bmp</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsImage</param-name>
<param-value></param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFlash</param-name>
<param-value>swf|fla</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFlash</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>com.action.AdminServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>SystemServlet</servlet-name>
<servlet-class>com.action.SystemServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>BulletinServlet</servlet-name>
<servlet-class>com.action.BulletinServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>ZiliaoServlet</servlet-name>
<servlet-class>com.action.ZiliaoServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>JianzhangServlet</servlet-name>
<servlet-class>com.action.JianzhangServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>StuServlet</servlet-name>
<servlet-class>com.action.StuServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.action.LoginServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>StuManageServlet</servlet-name>
<servlet-class>com.action.StuManageServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>HkServlet</servlet-name>
<servlet-class>com.action.HkServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>
/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>
/FCKeditor/editor/filemanager/upload/simpleuploader
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/Admin.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SystemServlet</servlet-name>
<url-pattern>/System.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>BulletinServlet</servlet-name>
<url-pattern>/BulletinServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JianzhangServlet</servlet-name>
<url-pattern>/JianzhangServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ZiliaoServlet</servlet-name>
<url-pattern>/ZiliaoServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StuServlet</servlet-name>
<url-pattern>/Stu.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/Login.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StuManageServlet</servlet-name>
<url-pattern>/StuManage.shtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HkServlet</servlet-name>
<url-pattern>/HkServlet</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/FCKeditor.tld</taglib-uri>
<taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
6、最终效果
6.1前台用户效果
6.2后台管理员用户效果