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

点赞再看,养成习惯

项目介绍

项目适用人群

正在做毕设的学生,或者需要项目实战练习的Java学习者

开发环境:

  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小哥来教你

项目截图

  • 注册

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

  • 系统管理

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

  • 新增/修改用户

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

  • 正式党员信息

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

  • 公告管理

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

  • 文件管理

【Java】党员系统怎么写,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.党费信息Servlet

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.文件下载

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版本后续迭代更新,持续关注

以上是 【Java】党员系统怎么写,java小哥来教你 的全部内容, 来源链接: utcz.com/a/90587.html

回到顶部