JavaWeb课程设计——基于Jsp+Servlet+MySQL的科研申报系统课程设计

Posted 那条学长V

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb课程设计——基于Jsp+Servlet+MySQL的科研申报系统课程设计相关的知识,希望对你有一定的参考价值。

​项目类型:JAVA WEB项目
项目名称:基于Jsp+Servlet的教师科研成果申报系统

用户类型:3个角色(管理员+教师+审批人)
系统类型:后台管理系统
设计模式:jsp+Servlet+MVC
开发工具:Eclipse/Idea均可以导入使用
数据库mysql+Navicat
数据库表:4张
适用:软件工程、计算机科学与技术等JAVA课程的学习和实验

PS:本系统基于web环境,在开发语言方面,由于Java的可移植性好,可在各个操作系统之间进行无障碍的转换,具有多操作系统性,因而选择Java作为本系统的开发语言。本系统的开发过程与一般的软件开发类似,先进行系统的需求分析,再对系统进行总体设计,之后划分模块,最后再对每个单独的模块进行编码与开发。而这一系列的设计过程都与一般的系统设计相同。并且Idea和Eclipse均可以使用

 作者介绍:计科,双1流高校毕业的学长,曾经也是个小白!

🍅 关注获取地址:(博主公众号——学长源码)查看更多项目

  • 关注回复    练习   免费get    教研评教系统(课程设计学习项目)(开源)
  • 关注回复    学生   免费get   一套JavaWeb源码
  • 关注回复    ppt     免费get   367套毕设答辩ppt模板
  • 关注回复   简历    免费get   200套程序猿简历模板

 🍅 更多毕业设计源码链接

目录

管理员端功能介绍

登录

申报图表统计

教师管理

添加教师

评审人员管理

添加评审人员

在线下载资料

管理员信息修改

教师端功能介绍

申报科研信息

个人信息修改

申报列表

审批人端功能介绍

项目申报审批

通过与驳回

数据库设计

项目结构

部分代码

TeacherServlet.java


管理员端功能介绍

登录

申报图表统计

教师管理

添加教师

评审人员管理

添加评审人员

在线下载资料

管理员信息修改

教师端功能介绍

申报科研信息

个人信息修改

申报列表

审批人端功能介绍

项目申报审批

通过与驳回

数据库设计

项目结构

 

部分代码

TeacherServlet.java

package edu.school.servlet;

import edu.school.entity.PageTool;
import edu.school.entity.Teacher;
import edu.school.service.TeacherService;
import edu.school.service.impl.TeacherServiceImpl;
import edu.school.utils.WebUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

//处理教师的业务
public class TeacherServlet extends BaseServlet {
    private TeacherService service=new TeacherServiceImpl();

    //分页查询教师信息
    protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//跳转到注册界面
        int totalCount=service.queryCount();
        //2.获取的当前页码,这个是从页面获取的
        String currentPage = request.getParameter("currentPage");
        PageTool pageTool=new PageTool(totalCount, currentPage);
        List<Teacher> TeacherList=service.findAllByPage(pageTool);
        //2.存储到域对象中
        request.setAttribute("teacherList", TeacherList);
        //将分页信息存储
        request.setAttribute("pageTool", pageTool);
        //将模糊查询的结构存储起来
        //3.通过请求转发
        request.getRequestDispatcher("/WEB-INF/teacher/teacher_list.jsp").forward(request, response);
    }


   protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("utf-8");
            Teacher teacher = fileUpload(request);
            service.addTeacher(teacher);
            response.sendRedirect(request.getContextPath()+"/TeacherServlet?action=list");//重定向防止重复提交哦
        } catch (Exception e) {
            e.printStackTrace();

        }
        return;
    }

    //上传头像
   private Teacher fileUpload(HttpServletRequest request) {

        Teacher teacher=new Teacher();
        try {
            request.setCharacterEncoding("utf-8");
            DiskFileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<FileItem> list = upload.parseRequest(request);
            for(FileItem item : list){
                if(item.isFormField()){
                    String name = item.getFieldName();
                    String value = item.getString("UTF-8");
                    BeanUtils.setProperty(teacher, name, value);
                }else{
                    String filename = item.getName();
                    //*	String savefilename = makeFileName(filename);*//*
                    String savepath="G:\\\\project\\\\教师申报系统\\\\jygh\\\\web\\\\upload\\\\";
                    //*String savepath= this.getServletContext().getRealPath("/upload");//Tomcat虚拟路径*//*
                    InputStream in = item.getInputStream();
                    FileOutputStream out = new FileOutputStream(savepath + "\\\\" + filename);
                    int len = 0;
                    byte buffer[] = new byte[1024];
                    while((len = in.read(buffer)) > 0){
                        out.write(buffer, 0, len);
                    }
                    in.close();
                    out.close();
                    item.delete();
                    teacher.setImgUrl(filename);
                    System.out.println(teacher.getImgUrl()+savepath);
                }
            }
            return teacher;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }


    //根据id查询教师信息
     protected void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//查询数据并回显
         int id= WebUtils.parseInt(request.getParameter("id"),0);
         Teacher teacher=service.findById(id);
         request.setAttribute("teacher",teacher);
         request.getRequestDispatcher("/WEB-INF/teacher/edit_teacher.jsp").forward(request,response);
    }

    //修改个人信息
    protected void toEditTeacherInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//查询数据并回显
        /*int id= WebUtils.parseInt(request.getParameter("id"),0);
        Teacher Teacher=service.findById(id);
        request.setAttribute("teacher",Teacher);*/
        request.getRequestDispatcher("/WEB-INF/teacher/edit_myinfo.jsp").forward(request,response);
    }


    //编辑教师信息
    protected void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            request.setCharacterEncoding("utf-8");
            String id = request.getParameter("ids");
            String tno = request.getParameter("tno");
            String pwd = request.getParameter("pwd");
            String name = request.getParameter("name");
            String sex = request.getParameter("sex");
            String phone = request.getParameter("phone");
            String major = request.getParameter("major");
            String detail = request.getParameter("detail");
           // Teacher teacher = fileUpload(request);
            Teacher teacher= new Teacher();
            teacher.setPwd(pwd);
            teacher.setTno(tno);
            teacher.setId(Integer.parseInt(id));
            teacher.setMajor(major);
            teacher.setSex(sex);
            teacher.setDetail(detail);
            teacher.setName(name);
            teacher.setPhone(phone);
            Object type = request.getSession().getAttribute("type");
           // String type=request.getParameter("type");
            service.updateTeacher(teacher);
            request.setAttribute("teacher",teacher);
            request.getSession().setAttribute("teacher",teacher);
            if (type != null && type.toString().equals("2")) {
               // request.getRequestDispatcher("/WEB-INF/teacher/edit_success.jsp").forward(request,response);
                request.getRequestDispatcher("/WEB-INF/teacher/edit_myinfo.jsp").forward(request,response);
            }else {
                response.sendRedirect(request.getContextPath()+"/TeacherServlet?action=list");//重定向防止重复提交哦
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
        return;
    }

   /* protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//更改
        int id= WebUtils.parseInt(request.getParameter("id"),0);
        String tno=request.getParameter("tno");
        String name=request.getParameter("name");
        String pwd=request.getParameter("pwd");
        String sex=request.getParameter("sex");
        String major=request.getParameter("major");
        String detail=request.getParameter("detail");
        String phone=request.getParameter("phone");
        String type=request.getParameter("type");
        if (type.equals("3")) {
            service.addTeacher(new Teacher(id,tno,pwd,name,sex,major,detail,phone,null));
            request.getRequestDispatcher("/WEB-INF/teacher/edit_success.jsp").forward(request,response);
        }else {
            service.addTeacher(new Teacher(id,tno,pwd,name,sex,major,detail,phone,null));
            response.sendRedirect(request.getContextPath()+"/TeacherServlet?action=list");//重定向防止重复提交哦
        }



    }*/
    //删除学生信息
    protected void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//根据id删除
        int id= WebUtils.parseInt(request.getParameter("id"),0);
        service.deleteTeacher(id);
        response.sendRedirect(request.getContextPath()+"/TeacherServlet?action=list"); //重定向防止重复提交哦
    }

    //根据工号和教师姓名查询
    protected void findByMap(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//条件查询
        String tno=request.getParameter("tno");
        String name=request.getParameter("tname");
        List<Teacher> list=service.findByMap(tno,name);
        if(null == list || list.size() ==0 ){
            request.setAttribute("msg" ,"无此信息");
            request.getRequestDispatcher("/WEB-INF/teacher/list_teacher.jsp").forward(request, response);
        }else {
            request.removeAttribute("msg");
            request.setAttribute("list" ,list);
            request.getRequestDispatcher("/WEB-INF/teacher/list_teacher.jsp").forward(request, response);
        }
    }

    
  //跳转到添加教师界面
    protected void toAddTeacher(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//跳转到添加用户界面
        request.getRequestDispatcher("/WEB-INF/teacher/add_teacher.jsp").forward(request,response);
    }

    
  
}

以上是关于JavaWeb课程设计——基于Jsp+Servlet+MySQL的科研申报系统课程设计的主要内容,如果未能解决你的问题,请参考以下文章

求推荐论坛或者网站可以找到计算机的课程设计或者毕业设计啊?

计算机课程设计-基于javaweb的在线点餐系统-线上点餐系统代码java外卖点餐系统代码

014基于JavaWeb的学生考勤系统(新版)

JavaWeb---总结(十四)JSP原理

20160327javaweb 之JSP入门

基于javaweb jsp+servlet学生宿舍管理系统设计和实现