基于javaweb+mysql的jsp+servlet毕业设计管理系统(java+jsp+javascript+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet毕业设计管理系统(java+jsp+javascript+servlet+mysql)
项目介绍
本项目包含管理员、教师、学生三种角色;
管理员角色包含以下功能:
管理员登录,查看首页,学院管理,专业管理,班级管理,用户注册,发布校级通知等功能。
教师角色包含以下功能: 教师登录,查看首页,查看并修改个人信息,查看待审批课题,查看所带课题状态,查看已提交课题信息,消息管理等功能。
学生角色包含以下功能: 学生登录,查看首页,查看并修改个人信息,查看选题信息,查看开题报告,查看中期检查,下载论文,消息管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈 JSP+CSS+JavaScript+servlet+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中Connector.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/jsp_bysjsys/ 登录 学生账号/密码: student/123456 指导教师账号/密码: teacher/123456 管理员账号/密码:admin/admin
<li><a HREF="viewreport">开题报告</a></li>
<li><a HREF="viewinspect">中期检查</a></li>
<li><a HREF="mypaper">论文</a></li>
<li><a HREF="message">消息</a></li>
</s:elseif>
<s:elseif test='#session.loginUser.role=="teacher"'>
<li class="current"><a HREF="userinfo">个人信息</a></li>
<li><a HREF="approval">待我审批</a></li>
<li><a HREF="tasksoftea">课题状态</a></li>
<li><a HREF="message">消息</a></li>
</s:elseif>
<s:elseif test='#session.loginUser.role=="deptadmin"'>
<li class="current"><a HREF="userinfo">个人信息</a></li>
<li><a HREF="approval">待我审批</a></li>
<li><a HREF="notice.jsp">发布院级通知</a></li>
</s:elseif>
</ul>
</nav>
<!-- End of Main navigation -->
<!-- Aside links -->
<aside>
<b>欢迎您:</b>
<a href="#">
<s:if test="#session.loginUser.realname==null">
<s:property value="#session.loginUser.username" />
</s:if>
<s:else>
<s:property value="#session.loginUser.realname" />
</s:else>
</a>·
<b>身份:</b>
<a href="#">
<s:if test='#session.loginUser.role=="sysadmin"'>
系统管理员
</s:if>
<s:elseif test='#session.loginUser.role=="student"'>
学生
</s:elseif>
<s:elseif test='#session.loginUser.role=="teacher"'>
导师
</s:elseif>
private static final String GET_NOTICE_LIST = "select noticeid,ntitle,scope,time from notice where scope = ? order by noticeid desc limit ?,?";
private static final String GET_NOTICE_BY_ID = "select * from notice where noticeid=?";
private Connector connector;
public NoticeDAO() {
this.connector = new Connector();
}
/**
* 向notice表中插入新数据
* @param notice 通知对象
* @throws Exception
*/
public void insert(Notice notice) throws Exception {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = this.connector.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(INSERT_NOTICE);
ps.setString(1, notice.getNtitle());
ps.setString(2, notice.getScope());
ps.setString(3, notice.getNcontent());
if (ps.execute()) {
conn.rollback();
System.out.println("--更新通知信息失败。");
} else {
System.out.println("--更新通知信息成功。");
conn.commit();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
throw new Exception(e);
} finally {
connector.closePreparedStatement(ps);
connector.closeConnection(conn);
}
}
/**
* 分页显示通知列表
* @param i 从第几项开始
* @param j 每页的行数
* @param scope 通知的范围(校级,院级)
* @return
* @throws SQLException
if (ps.execute()) {
conn.rollback();
System.out.println("--插入专业信息失败。");
} else {
System.out.println("--插入专业信息成功。");
conn.commit();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
throw new SQLException(e);
} finally {
connector.closePreparedStatement(ps);
connector.closeConnection(conn);
}
}
public void deleteDeptByID(String deptid) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = this.connector.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(DELETE_DELETE_BY_ID);
ps.setString(1, deptid);
if (ps.execute()) {
conn.rollback();
System.out.println("--删除专业信息失败。");
} else {
System.out.println("--删除专业信息成功。");
conn.commit();
conn.setAutoCommit(true);
}
$.ajax({
url: 'modifypwd',
type: 'post',
data: {
newpwd : newpwd,
conpwd : conpwd,
},
success : function(str){
$("#message").show(500);
$("#message").html(str);
$("#message").hide(3000);
}
});
}
/* 修改联系方式,ajax */
function modifycontact(){
var email = $("#email").val();
var telphone = $("#telphone").val();
$.ajax({
url: 'modifycontact',
type: 'post',
data: {
email : email,
telphone : telphone,
},
success : function(str){
$("#message").show(500);
$("#message").html(str);
$("#message").hide(3000);
}
});
}
</script>
<body>
<!-- Header -->
<header id="top">
<div class="wrapper">
<!-- Title/Logo - can use text instead of image -->
<div id="title"><span>毕业设计管理系统</span></div>
<!-- Top navigation -->
<div id="topnav">
<a href="#"><img class="avatar" SRC="img/user_32.png" alt="" /></a>
<b>
<s:if test='#session.loginUser.role=="sysadmin"'>
系统管理员
</s:if>
<s:elseif test='#session.loginUser.role=="student"'>
学生
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(src), BUFFER_SIZE );
out = new BufferedOutputStream( new FileOutputStream(dst),
BUFFER_SIZE );
byte [] buffer = new byte [ BUFFER_SIZE ];
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if ( null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if ( null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public File getAttach() {
return attach;
}
public void setAttach(File attach) {
this.attach = attach;
}
public String getAttachFileName() {
return attachFileName;
}
report = reportDao.getReportByTaskid(task.getTaskid());
if(report == null){
message = "开题报告还未提交,请查看选题信息";
return "success";
} else {
return "viewreport";
}
} catch (SQLException e) {
e.printStackTrace();
message = "系统错误";
return "notexist";
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTaskid() {
return taskid;
}
public void setTaskid(String taskid) {
this.taskid = taskid;
}
public Task getTask() {
return task;
}
public void setTask(Task task) {
}
public String notexist(){
return "notexist";
}
public Notice getNotice() {
return notice;
}
public void setNotice(Notice notice) {
this.notice = notice;
}
public String getNtitle() {
return ntitle;
}
public void setNtitle(String ntitle) {
this.ntitle = ntitle;
}
public String getNcontent() {
return ncontent;
}
public void setNcontent(String ncontent) {
this.ncontent = ncontent;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getScope() {
return scope;
}
ps.setString(1, tasktitle);
ps.setString(2, summary);
ps.setString(3, username);
ps.setString(4, teaid);
if (ps.execute()) {
conn.rollback();
System.out.println("--插入课题信息失败。");
} else {
System.out.println("--插入课题信息成功。");
conn.commit();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
throw new SQLException(e);
} finally {
connector.closePreparedStatement(ps);
connector.closeConnection(conn);
}
}
public boolean isExist(String username) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(TASK_IS_EXIST);
ps.setString(1, username);
rs = ps.executeQuery();
rs.next();
if (rs.getInt(1) == 1) {
System.out.println("--此学生已提交课题");
return true;
} else {
System.out.println("此班级编号已存在");
return true;
} else {
return false;
}
} catch (SQLException e){
e.printStackTrace();
} finally {
this.connector.closeResultSet(rs);
this.connector.closePreparedStatement(ps);
this.connector.closeConnection(conn);
}
return false;
}
public void insertClass(String classid, String classname, String deptid) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = this.connector.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(INSERT_NEW_CLASS);
ps.setString(1, classid);
ps.setString(2, classname);
ps.setString(3, deptid);
if (ps.execute()) {
conn.rollback();
System.out.println("--插入班级信息失败。");
} else {
System.out.println("--插入班级信息成功。");
conn.commit();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
throw new SQLException(e);
newPaperName = BaseUnit.getLoginUser().getUsername() + "-" + new Random().nextInt(999999) + "." + suffix;
String dstPath = ServletActionContext.getServletContext().getRealPath(this.getSavePath())
+ "/" + newPaperName;
File dstFile = new File(dstPath);
copy(this.paper, dstFile);
PaperDAO paperDao = new PaperDAO();
TaskDAO taskDao = new TaskDAO();
try {
paperDao.insertPaper(taskid, paperFileName, newPaperName);
taskDao.updateStatus(taskid, "8"); //修改课题状态
} catch (SQLException e) {
e.printStackTrace();
message = "系统错误";
return "notexist";
}
message = "上传论文成功!";
return "success";
}
public String toDownloadPage(){
TaskDAO taskDao = new TaskDAO();
PaperDAO paperDao = new PaperDAO();
try {
if (taskid == "" || taskid == null) {
task = taskDao.getTaskByUsername(BaseUnit.getLoginUser().getUsername());
} else {
task = taskDao.getTaskByID(taskid);
}
if (task == null){
message = "还没有申请课题,请查看选题信息";
return "success";
}
mypaper = paperDao.getPaperByTaskid(task.getTaskid());
if(mypaper == null){
message = "论文还未上传,请查看选题信息";
return "success";
} else {
return "todownloadpage";
}
} catch (SQLException e) {
e.printStackTrace();
message = "系统错误";
return "notexist";
public class DeptDAO {
private static final String GET_DEPTS_LIST = "select * from dept where collegeid=?";
private static final String GET_DEPT_NAME_BY_ID = "select dname from dept where deptid=?";
private static final String DEPT_IS_EXIST = "select count(*) from dept where deptid=?";
private static final String INSERT_NEW_DEPT = "insert into dept values(?,?,?)";
private static final String DELETE_DELETE_BY_ID = "delete from dept where deptid=?";
private Connector connector;
public DeptDAO() {
this.connector = new Connector();
}
public StringBuffer getDeptsByCollegeidForAjax(String collegeid) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
StringBuffer sb = new StringBuffer();
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(GET_DEPTS_LIST);
ps.setString(1, collegeid);
rs = ps.executeQuery();
while (rs.next()) {
sb.append( rs.getString( "deptid" ) + ","
+ rs.getString( "dname" ) );
if ( !rs.isLast() ) sb.append( "|" );
}
System.out.println("--获取专业字符串成功。");
} catch (SQLException e){
System.out.println("--获取专业字符串失败。");
e.printStackTrace();
} finally {
this.connector.closeResultSet(rs);
this.connector.closePreparedStatement(ps);
this.connector.closeConnection(conn);
}
return sb;
}
public String getNameById(String deptid) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
teachers = userDao.getTeacherList(BaseUnit.getLoginUser().getCollegeid());
} catch (SQLException e) {
e.printStackTrace();
message = "获取学生所在院系的所有老师失败";
return "notexist";
}
return "success";
}
public String submitTaskTitle(){
UserDAO userDao = new UserDAO();
if("0".equals(teaid)){
try {
teachers = userDao.getTeacherList(BaseUnit.getLoginUser().getCollegeid());
} catch (SQLException e) {
e.printStackTrace();
message = "获取学生所在院系的所有老师失败";
return "notexist";
}
message = "请选择导师";
return "subtask";
}
TaskDAO taskDao = new TaskDAO();
if(taskDao.titleIsExist(tasktitle)){
try {
teachers = userDao.getTeacherList(BaseUnit.getLoginUser().getCollegeid());
} catch (SQLException e) {
e.printStackTrace();
message = "获取学生所在院系的所有老师失败";
return "notexist";
}
message = "此题目已有人提交,不可重复提交!";
return "subtask";
}
try {
taskDao.insertTask(tasktitle, BaseUnit.getLoginUser().getUsername(), teaid, summary);
message = "提交课题成功!";
function getclasslist(deptid){
$.get("getclasslist?deptid=" + deptid, function(data){
each = data.split("|");
sel = document.getElementById("classlist");
sel.options.length = 0;
if(each == ""){
sel.options[sel.options.length] = new Option("暂时没有班级","0");
} else {
sel.options[sel.options.length] = new Option("--请选择所在班级--","0");
for(var i = 0; i < each.length; i++){
strs = each[i].split(",");
sel.options[sel.options.length] = new Option(strs[0] + "-" + strs[1],strs[0]);
}
}
});
}
/* 提交注册表单,ajax */
function sub(){
var username = $("#username").val();
var role = $("#role").val();
var realname = $("#realname").val();
var collegeid = $("#colleges").val();
var deptid = $("#deptlist").val();
var classid = $("#classlist").val();
$.ajax({
url: 'register',
type: 'post',
data: {
username : username,
role : role,
realname : realname,
collegeid : collegeid,
deptid : deptid,
classid : classid
},
success : function(str){
$("#message").show(500);
$("#message").html(str);
$("#message").hide(3000);
}
});
}
ResultSet rs = null;
List<Message> messages = new ArrayList<Message>();
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(GET_INBOX_MESSAGELIST);
ps.setString(1, username);
rs = ps.executeQuery();
while (rs.next()) {
Message message = new Message(rs.getString("messageid"), rs.getString("fromid"), rs.getString("toid"),
rs.getString ("title"), rs.getString("content"), rs.getString("filename"),
rs.getString ("newname"), rs.getDate("subtime").toString() + " " + rs.getTime("subtime").toString());
messages.add(message);
}
System.out.println("--获取收件箱列表成功。");
} catch (SQLException e){
System.out.println("--获取收件箱列表失败。");
throw new SQLException(e);
} finally {
this.connector.closeResultSet(rs);
this.connector.closePreparedStatement(ps);
this.connector.closeConnection(conn);
}
return messages;
}
public List<Message> getOutbox(String username) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Message> messages = new ArrayList<Message>();
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(GET_OUTBOX_MESSAGELIST);
ps.setString(1, username);
rs = ps.executeQuery();
while (rs.next()) {
public class MessageAction extends ActionSupport{
private static final long serialVersionUID = -7068584475342566206L;
private static final int BUFFER_SIZE = 16 * 1024;
private File attach;
private String attachFileName;
private String newattachName;
private String attachContentType;
private String savePath;
private String messtitle;
private String mystus;
private String messcontent;
private String messageid;
private Message mess; //用户发送的短信息
private String fromname; //发件人姓名
private String toname; //收件人姓名
private String message; //提示信息
private List<User> students = null;
private List<Message> inbox = null;
private List<Message> outbox = null;
public String sendMessage(){
User user = BaseUnit.getLoginUser();
MessageDAO messDao = new MessageDAO();
TaskDAO taskDao = new TaskDAO();
String fromid = user.getUsername();;
String toid = "";
}
public Inspection getInspect() {
return inspect;
}
public void setInspect(Inspection inspect) {
this.inspect = inspect;
}
public String getProgress() {
return progress;
}
public void setProgress(String progress) {
this.progress = progress;
}
public String getProblem() {
return problem;
}
public void setProblem(String problem) {
this.problem = problem;
}
}
public class LoginAction{
private static final String LOGIN = "login";
private static final String LOGOUT = "logout";
private List<Notice> alllist = null; //首页校级通知列表
private List<Notice> collegelist = null; //首页院级通知列表
private User user;
private String message;
private String username; //登录页中获取的用户名
private String password; //登录页中获取的密码
* @param scope 通知的范围(校级,院级)
* @return
* @throws SQLException
*/
public List<Notice> getNoticeList(int i, int j, String scope) throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Notice> noticeList = new ArrayList<Notice>();
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(GET_NOTICE_LIST);
ps.setString(1, scope);
ps.setInt(2, i);
ps.setInt(3, j);
rs = ps.executeQuery();
while (rs.next()) {
Notice notice = new Notice();
notice.setNoticeid(rs.getInt("noticeid"));
notice.setNtitle(rs.getString("ntitle"));
notice.setScope(rs.getString("scope"));
notice.setTime(rs.getDate("time").toString() + " " + rs.getTime("time").toString());
noticeList.add(notice);
}
System.out.println("--获取通知列表成功。");
} catch (SQLException e){
System.out.println("--获取通知列表失败。");
throw new SQLException(e);
} finally {
this.connector.closeResultSet(rs);
this.connector.closePreparedStatement(ps);
this.connector.closeConnection(conn);
}
return noticeList;
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(GET_CLASS_NAME_BY_ID);
ps.setString(1, classid);
rs = ps.executeQuery();
if (rs.next()) {
System.out.println("--获取班级名成功");
return rs.getString("cname");
} else {
System.out.println("--获取班级名失败");
return "";
}
} catch (SQLException e){
throw new SQLException(e);
} finally {
this.connector.closeResultSet(rs);
this.connector.closePreparedStatement(ps);
this.connector.closeConnection(conn);
}
}
public boolean isExist(String classid) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = this.connector.getConnection();
ps = conn.prepareStatement(CLASS_IS_EXIST);
ps.setString(1, classid);
rs = ps.executeQuery();
rs.next();
if (rs.getInt(1) == 1) {
System.out.println("此班级编号已存在");
return true;
} else {
return false;