党员系统怎么写,java小哥来教你

2021年11月23日 阅读数:4
这篇文章主要向大家介绍党员系统怎么写,java小哥来教你,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

点赞再看,养成习惯前端

项目介绍

入党信息管理系统采用jsp+servlet搭建,mysql作数据支持,jsp作前端数据渲染,实现不用角色不一样的条件查询,展现对应的页面和数据。本系统应用于院校的入党信息管理,目前实现了我的管理、系统管理、支部信息管理、入党积极分子信息、预备党员信息、正式党员信息、党费信息、公告管理、文件管理等功能,有时间在作进一步的完善。java

项目适用人群

正在作毕设的学生,或者须要项目实战练习的Java学习者mysql

开发环境:

  1. jdk 8
  2. intellij idea
  3. tomcat 8.5.40
  4. mysql 5.7

所用技术:

  1. jsp+servlet
  2. js+ajax
  3. layUi
  4. jdbc直连

项目访问地址

http://localhost:8090

项目结构

党员系统怎么写,java小哥来教你

项目截图

  • 注册
    党员系统怎么写,java小哥来教你
    ajax

  • 系统管理

党员系统怎么写,java小哥来教你

  • 新增/修改用户

党员系统怎么写,java小哥来教你

  • 正式党员信息
    党员系统怎么写,java小哥来教你
    spring

  • 公告管理
    党员系统怎么写,java小哥来教你
    sql

  • 文件管理
    党员系统怎么写,java小哥来教你

关键代码:

1.初始化工做数据库

//数据库链接初始化
public Connection getConnection() {
    Connection conn = null;
    String sDBDriver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/schooldb?useUnicode=true&characterEncoding=utf8";
    try {
        //加载数据库驱动
        Class.forName(sDBDriver);
        //获取数据库连接 -帐号-密码
        conn = DriverManager.getConnection(url, "root", "root123");
        return conn;
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("数据库驱动注册错误信息: " + e.getMessage());
    }
    return conn;
}

2.党费信息Servlettomcat

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String mtype = request.getParameter("mtype");
        String url = "";
        DangfeiDao dangfeiDao = new DangfeiDao();
        /**
         * 添加党费信息
         */
        if ("add".equals(mtype)) {
            TDangfei dangfei = new TDangfei();
            dangfei.setTypeid(request.getParameter("typeid"));
            dangfei.setClassname(request.getParameter("classname"));
            dangfei.setDangfei(request.getParameter("dangfei"));
            dangfei.setDangtype(request.getParameter("dangtype"));
            dangfei.setShouyear(request.getParameter("shouyear"));
            dangfei.setTypename(request.getParameter("typename"));
            dangfei.setUsername(request.getParameter("username"));
            dangfeiDao.addDangfei(dangfei);
            url = "/DangfeiServlet?mtype=query&flag=success";
            /**
             * 初始化修改党费信息界面
             */
        } else if ("preupdate".equals(mtype)) {
            request.setAttribute("dangfei", dangfeiDao.getDangfei(request.getParameter("id")));
            url = "/files/dangfei/update.jsp";

            /**
             * 修改党费信息
             */
        } else if ("update".equals(mtype)) {
            TDangfei dangfei = new TDangfei();
            dangfei.setId(Integer.parseInt(request.getParameter("id")));
            dangfei.setTypeid(request.getParameter("typeid"));
            dangfei.setClassname(request.getParameter("classname"));
            dangfei.setDangfei(request.getParameter("dangfei"));
            dangfei.setDangtype(request.getParameter("dangtype"));
            dangfei.setShouyear(request.getParameter("shouyear"));
            dangfei.setTypename(request.getParameter("typename"));
            dangfei.setUsername(request.getParameter("username"));
            dangfeiDao.updateDangfei(dangfei);
            url = "/DangfeiServlet?mtype=query";
            /**
             * 遍历党费信息
             */
        } else if ("query".equals(mtype)) {
            if (request.getSession().getAttribute("querypageunit") == null) {
                request.getSession().setAttribute("querypageunit",
                        this.pageunit);
            }
            int curpage = this.getCurrentpage(request);
            int pageunit = this.getPageunit(request, "querypageunit");

            String urlpage = "DangfeiServlet?mtype=query";
            StringBuffer cond = new StringBuffer();
            if (null != request.getParameter("searchname") && "" != request.getParameter("searchname").trim()) {
                cond.append(" and a.typename like '%" + request.getParameter("searchname").trim() + "%' ");
            }
            if (null != request.getSession().getAttribute("usertype") && !"0".equals(((String) request.getSession().getAttribute("usertype")))) {
                cond.append(" and a.typeid like '%" + (String) request.getSession().getAttribute("typeid") + "%' ");
            }
            PageInfo pageInfo = dangfeiDao.queryTDangfei(curpage,
                    pageunit, request, urlpage, cond.toString());
            request.setAttribute("pageinfo", pageInfo);
            request.setAttribute("searchname", request.getParameter("searchname"));
            url = "/files/dangfei/list.jsp";
            /**
             * 删除党费信息
             */
        } else if ("delete".equals(mtype)) {
            dangfeiDao.delDangfei(request.getParameter("id"));
            url = "/DangfeiServlet?mtype=query";
        }
        //重定向到目标地址
        RequestDispatcher dispatcher = request.getRequestDispatcher(url);
        dispatcher.forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

3.文件下载springboot

public void doGet(HttpServletRequest request, HttpServletResponse response)throws  IOException {
    //得到请求文件名  
    request.setCharacterEncoding("ISO-8859-1");
    String filename = request.getParameter("filename");
    filename = new String(filename.getBytes("ISO-8859-1"), "UTF-8");

    //设置文件MIME类型
    response.setContentType(getServletContext().getMimeType(filename));
    //设置Content-Disposition
    response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes("GBK"), "ISO-8859-1"));
    //读取目标文件,经过response将目标文件写到客户端
    //获取目标文件的绝对路径

    String fullFileName = getServletContext().getRealPath("/upload/" + filename);
    //读取文件
    InputStream in = new FileInputStream(fullFileName);
    OutputStream out = response.getOutputStream();

    //写文件
    int b;
    while ((b = in.read()) != -1) {
        out.write(b);
    }

    in.close();
    out.close();
}

项目后续

其余ssh,ssm,springboot版本后续迭代更新,持续关注app