JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap.
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户模块的DAO层(数据层)的具体实现类,对UserDAO接口中定义的增删改查等抽象方法作出具体的功能实现
*/
public class UserDAOImpl implements UserDAO {
ps.setString(3, vo.getRealName());
ps.setString(4, vo.getUserSex());
ps.setString(5, vo.getUserPhone());
ps.setString(6, vo.getUserText());
ps.setString(7, vo.getUserType());
ps.setLong(8, vo.getId());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
public boolean delete(long id) {
try {
}
</script>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>用户管理</title>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
<div class="index-content-operation">
<a class="info-detail">用户管理</a>
<br>
<br>
</div>
<br>
<div class="index-content-operation">
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//过滤编码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String action = Util.decode(request, "action");
if ("add".equals(action)) {//增加
User vo = new User();
//取出页面传进来的各个数据,并设置到User对象的属性里
vo.setUsername(Util.decode(request, "username"));
vo.setPassword(Util.decode(request, "password"));
vo.setRealName(Util.decode(request, "realName"));
vo.setUserSex(Util.decode(request, "userSex"));
vo.setUserPhone(Util.decode(request, "userPhone"));
vo.setUserText(Util.decode(request, "userText"));
vo.setUserType(Util.decode(request, "userType"));
UserService userService = new UserServiceImpl();
//调用Service层增加方法(add),增加记录
userService.add(vo);
this.redirectList(request, response);
} else if ("delete".equals(action)) {//删除
//取出表要删除的用户记录的主键
long id = Long.parseLong(Util.decode(request, "id"));
UserService userService = new UserServiceImpl();
//调用Service层删除方法(delete),将对应的记录删除
userService.delete(id);
this.redirectList(request, response);
} else if ("edit".equals(action)) {//修改
//取出页面传进来的各个数据,并设置到User对象的属性里
User vo = new User();
vo.setId(Long.valueOf(Util.decode(request, "id")));
vo.setUsername(Util.decode(request, "username"));
vo.setPassword(Util.decode(request, "password"));
vo.setRealName(Util.decode(request, "realName"));
* 处理Post请求
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//过滤编码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String action = Util.decode(request, "action");
if ("add".equals(action)) {//增加
User vo = new User();
//取出页面传进来的各个数据,并设置到User对象的属性里
vo.setUsername(Util.decode(request, "username"));
vo.setPassword(Util.decode(request, "password"));
vo.setRealName(Util.decode(request, "realName"));
vo.setUserSex(Util.decode(request, "userSex"));
vo.setUserPhone(Util.decode(request, "userPhone"));
vo.setUserText(Util.decode(request, "userText"));
vo.setUserType(Util.decode(request, "userType"));
ps.setString(1, vo.getShouruName());
ps.setString(2, vo.getShouruJinge());
ps.setString(3, vo.getShouruFangshi());
ps.setString(4, vo.getShouruTime());
ps.setString(5, vo.getShouruText());
ps.setLong(6, vo.getId());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
try {
Connection c = Util.getConnection();
Statement s = c.createStatement();
String sql = "delete from `t_shouru` where id = " + id;
s.execute(sql);
s.close();
c.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
<th>备注</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="vo">
<tr class="index-content-table-td">
<td>${vo.zhichuName}</td>
<td>${vo.zhichuJine}</td>
<td>${vo.zhichuFangshi}</td>
<td>${vo.zhichuTime}</td>
<td title="${vo.zhichuText}">
<c:choose>
<c:when test="${fn:length(vo.zhichuText) > 19}">
<c:out value="${fn:substring(vo.zhichuText, 0, 19)}..."/>
</c:when>
<c:otherwise>
<c:out value="${vo.zhichuText}"/>
</c:otherwise>
</c:choose>
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 公告模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>
* 而后再调用NoticeService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面
*/
//@WebServlet("/NoticeServlet")
public class NoticeServlet extends HttpServlet {
/**
* 处理Post请求
*
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("NoticeServlet");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("notice_list.jsp");
}
}
package com.demo.dao.impl;
import com.demo.util.Util;
import com.demo.dao.UserDAO;
import com.demo.vo.User;
import java.io.Serializable;
request.getRequestDispatcher("register.jsp").forward(request, response);
return;
}
}
User vo = new User();
vo.setUsername(username);
vo.setPassword(password);
//vo.setUserType("普通用户");//需要设置一个默认值
userService.add(vo);
request.getSession().setAttribute("alert_msg", "注册成功!用户名:[" + username + "]");
import com.demo.vo.User;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户模块的DAO层(数据层)的具体实现类,对UserDAO接口中定义的增删改查等抽象方法作出具体的功能实现
*/
public class UserDAOImpl implements UserDAO {
//@Override
public void add(User vo) {
<title>收入管理</title>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
<div class="index-content-operation">
<a class="info-detail">收入管理</a>
<br>
<br>
</div>
<br>
<div class="index-content-operation">
<button class="btn btn-pill btn-danger btn-sm" <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"</c:if> οnclick="window.location.href='shouru_add.jsp'">添加</button>
<div class="index-content-operation-search"><input id="search_keyword" placeholder="标题" type="text" name="search_keyword"/><input type="hidden" id="searchColumn" name="searchColumn" value="shouru_name"/><button class="btn btn-pill btn-default btn-sm" onclick="searchList()">搜索</button></div>
</div>
<br>
<table class="table table-striped table-hover table-bordered">
<thead>
<tr class="index-content-table-th">
<th>标题</th>
<th>金额</th>
<th>收入方式</th>
<th>时间</th>
<script>
function searchList() {
window.location.href = "ShouruServlet?action=list&searchColumn="+document.getElementById("searchColumn").value+"&keyword=" + document.getElementById("search_keyword").value;
}
</script>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>支出管理</title>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
public static String PASSWORD = "123456";
/**
* 取得数据库连接对象
*
* @return 如果连接成功则返回连接对象,如果连接失败返回null
*/
public static Connection getConnection() throws Exception {
Class.forName(DBDRIVER);
return DriverManager.getConnection(DBURL, DBUSER, PASSWORD);
}
/**
* 测试连接是否成功
*
* @param args
* @throws Exception
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
<div class="index-content-operation">
<a class="info-detail">添加用户</a>
<br>
<br>
</div>
<br>
<form action="UserServlet?action=add" method="post" onsubmit="return check()">
<table class="index-content-table-add">
<tr>
<td width="12%">用户名:</td><td><input class="index-content-table-td-add" type="text" id="username" name="username" value=""/></td>
</tr>
<tr>
<td width="12%">密码:</td><td><input class="index-content-table-td-add" type="text" id="password" name="password" value=""/></td>
</tr>
<tr>
<td width="12%">姓名:</td><td><input class="index-content-table-td-add" type="text" id="realName" name="realName" value=""/></td>
</tr>
<tr>
<td width="12%">性别:</td>
import com.demo.util.Util;
import com.demo.service.ZhichuService;
import com.demo.service.impl.ZhichuServiceImpl;
import com.demo.vo.Zhichu;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 支出模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>
try {
Connection c = Util.getConnection();
Statement s = c.createStatement();
String sql = "select * from `t_zhichu` where id = " + id;
ResultSet rs = s.executeQuery(sql);
if (rs.next()) {
vo = new Zhichu();
vo.setId(rs.getLong("id"));
vo.setZhichuName(rs.getString("zhichu_name"));
vo.setZhichuJine(rs.getString("zhichu_jine"));
vo.setZhichuFangshi(rs.getString("zhichu_fangshi"));
vo.setZhichuTime(rs.getString("zhichu_time"));
vo.setZhichuText(rs.getString("zhichu_text"));
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
return vo;
}
//@Override
public Map<String, Object> list(Map<String, Object> params) {
* 公告模块的DAO层(数据层)的具体实现类,对NoticeDAO接口中定义的增删改查等抽象方法作出具体的功能实现
*/
public class NoticeDAOImpl implements NoticeDAO {
//@Override
public void add(Notice vo) {
String sql = "insert into `t_notice` (`notice_name`,`notice_text`,`notice_type`,`create_date`) values(?,?,?,?)";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
return false;
}
return true;
}
</script>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>添加用户</title>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
</head>
<body>
<jsp:include page="menu.jsp"/>
<div class="index-content">
<div class="index-content-operation">
import com.demo.service.impl.NoticeServiceImpl;
import com.demo.vo.Notice;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>收入管理</title>
<link rel="stylesheet" type="text/css" href="css/index.css"/>
e.printStackTrace();
}
Map<String, Object> result = new HashMap();
result.put("list", list);
result.put("totalCount", totalCount);
return result;
}
}
package com.demo.dao.impl;
import com.demo.util.Util;
import com.demo.dao.NoticeDAO;
import com.demo.vo.Notice;
} else if ("resetPassword".equalsIgnoreCase(action)) {
String msg;
User loginUser = (User) request.getSession().getAttribute("loginUser");
String oldPassword = Util.decode(request, "oldPassword");
if (!loginUser.getPassword().equals(oldPassword)) {
msg = "原密码错误!";
} else {
String newPassword = Util.decode(request, "newPassword");
loginUser.setPassword(newPassword);
UserService userService = new UserServiceImpl();
vo.setId(rs.getLong("id"));
vo.setUsername(rs.getString("username"));
vo.setPassword(rs.getString("password"));
vo.setRealName(rs.getString("real_name"));
vo.setUserSex(rs.getString("user_sex"));
vo.setUserPhone(rs.getString("user_phone"));
vo.setUserText(rs.getString("user_text"));
vo.setUserType(rs.getString("user_type"));
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
return vo;
}
//@Override
public Map<String, Object> list(Map<String, Object> params) {
List<User> list = new ArrayList();
int totalCount = 0;
String condition = "";
String sqlList;
if (params.get("searchColumn") != null && !"".equals(params.get("searchColumn"))) {
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap.
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、收入模块、支出模块的增删改查管理
↖[获取源码方式]见左侧