基于javaweb+mysql的jsp+servlet企业财务记账管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax)

本文主要是介绍基于javaweb+mysql的jsp+servlet企业财务记账管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

基于javaweb+mysql的jsp+servlet企业财务记账管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JavaBean MVC JSP Servlet MySQL CSS JavaScript Bootstrap Ajax

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

登录、注册、退出、用户模块、公告模块、职工工资模块、企业资产模块、项目经营模块的增删改查管理

eclipse/MyEclipse运行:

idea运行:

 * 而后再调用NoticeService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面*/
//@WebServlet("/NoticeServlet")
public class NoticeServlet extends HttpServlet {/*** 处理Post请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//过滤编码request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");String action = request.getParameter("action");if ("add".equals(action)) {//增加Notice vo = new Notice();//取出页面传进来的各个数据,并设置到Notice对象的属性里vo.setNoticeName(request.getParameter("noticeName"));vo.setNoticeText(request.getParameter("noticeText"));vo.setNoticeType(request.getParameter("noticeType"));vo.setCreateDate(request.getParameter("createDate"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层增加方法(add),增加记录noticeService.add(vo);this.redirectList(request, response);} else if ("delete".equals(action)) {//删除//取出表要删除的公告记录的主键long id = Long.parseLong(request.getParameter("id"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层删除方法(delete),将对应的记录删除noticeService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Notice对象的属性里Notice vo = new Notice();vo.setId(Long.valueOf(request.getParameter("id")));vo.setNoticeName(request.getParameter("noticeName"));vo.setNoticeText(request.getParameter("noticeText"));vo.setNoticeType(request.getParameter("noticeType"));vo.setCreateDate(request.getParameter("createDate"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层更新方法(update),更新记录noticeService.update(vo);this.redirectList(request, response);} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面Serializable id = request.getParameter("id");//取出页面传入的主键,用于查询详情NoticeService noticeService = new NoticeServiceImpl();Notice vo = noticeService.get(id);response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页String pageNum = request.getParameter("pageNum");//封装分页参数com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);params.put("startIndex", pb.getStartIndex());params.put("pageSize", pb.getPageSize());List list = (List) salaryService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果listpb.setServlet("SalaryServlet");pb.setSearchColumn(searchColumn);pb.setKeyword(keyword);pb.setList(list);request.getSession().setAttribute("pageBean", pb);request.getSession().setAttribute("list", pb.getList());response.sendRedirect("salary_list.jsp");}
}/*** 公告模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>* 而后再调用NoticeService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面*/
//@WebServlet("/NoticeServlet")
public class NoticeServlet extends HttpServlet {/*** 处理Post请求** @param request* @param response* @throws ServletException* @throws IOException*/@Override
     * @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好}/*** 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面** @param request* @param response*/private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {//查询列和关键字String searchColumn = request.getParameter("searchColumn");String keyword = request.getParameter("keyword");Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)params.put("searchColumn", searchColumn);//要查询的列params.put("keyword", keyword);//查询的关键字NoticeService noticeService = new NoticeServiceImpl();Map<String, Object> map = noticeService.list(params);request.getSession().setAttribute("list", map.get("list"));Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页String pageNum = request.getParameter("pageNum");//封装分页参数com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);params.put("startIndex", pb.getStartIndex());params.put("pageSize", pb.getPageSize());List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果listpb.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");}
}/*** 这是过滤器* 主要负责过滤编码为utf-8及登录拦截,禁止未登录就访问
                UserService userService = new UserServiceImpl();userService.update(loginUser);msg = "修改成功!";}request.getSession().setAttribute("alert_msg", msg);request.getRequestDispatcher("reset_password.jsp").forward(request, response);} else {response.sendRedirect("login.jsp");}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);}// 返回一个随机颜色(Color对象)private Color getRandomColor(int minColor, int maxColor) {Random random = new Random();// 保存minColor最大不会超过255if (minColor > 255)minColor = 255;//  保存minColor最大不会超过255if (maxColor > 255)maxColor = 255;//  获得红色的随机颜色值int red = minColor + random.nextInt(maxColor - minColor);//  获得绿色的随机颜色值int green = minColor + random.nextInt(maxColor - minColor);//  获得蓝色的随机颜色值int blue = minColor + random.nextInt(maxColor - minColor);return new Color(red, green, blue);
            this.redirectList(request, response);}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好}/*** 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面** @param request* @param response*/private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {//查询列和关键字String searchColumn = request.getParameter("searchColumn");String keyword = request.getParameter("keyword");Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)params.put("searchColumn", searchColumn);//要查询的列params.put("keyword", keyword);//查询的关键字NoticeService noticeService = new NoticeServiceImpl();Map<String, Object> map = noticeService.list(params);request.getSession().setAttribute("list", map.get("list"));Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页String pageNum = request.getParameter("pageNum");//封装分页参数com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);params.put("startIndex", pb.getStartIndex());params.put("pageSize", pb.getPageSize());List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果listpb.setServlet("NoticeServlet");
            String password = request.getParameter("password");String validationCode = request.getParameter("validationCode");if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");request.getRequestDispatcher("login.jsp").forward(request, response);return;}UserService userService = new UserServiceImpl();Map<String, Object> params = new HashMap();List<User> list = (List<User>) userService.list(params).get("list");for (User user : list) {if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了request.getSession().setAttribute("loginUser", user);request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);request.getRequestDispatcher("UserServlet").forward(request, response);return;}}request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");request.getRequestDispatcher("login.jsp").forward(request, response);} else if ("register".equalsIgnoreCase(action)) {//注册String username = request.getParameter("username");String password = request.getParameter("password");System.out.println("username=" + username);System.out.println("password=" + password);UserService userService = new UserServiceImpl();Map<String, Object> params = new HashMap();params.put("startIndex", 0);params.put("pageSize", Long.MAX_VALUE);List<User> list = (List<User>) userService.list(params).get("list");for (User user : list) {if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");request.getRequestDispatcher("register.jsp").forward(request, response);return;}}User vo = new User();
            String password = request.getParameter("password");String validationCode = request.getParameter("validationCode");if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");request.getRequestDispatcher("login.jsp").forward(request, response);return;}UserService userService = new UserServiceImpl();Map<String, Object> params = new HashMap();List<User> list = (List<User>) userService.list(params).get("list");for (User user : list) {if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了request.getSession().setAttribute("loginUser", user);request.getSession().setMaxInactiveInterval(Integer.MAX_VALUE);request.getRequestDispatcher("UserServlet").forward(request, response);return;}}request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");request.getRequestDispatcher("login.jsp").forward(request, response);} else if ("register".equalsIgnoreCase(action)) {//注册String username = request.getParameter("username");String password = request.getParameter("password");System.out.println("username=" + username);System.out.println("password=" + password);UserService userService = new UserServiceImpl();Map<String, Object> params = new HashMap();params.put("startIndex", 0);params.put("pageSize", Long.MAX_VALUE);List<User> list = (List<User>) userService.list(params).get("list");for (User user : list) {if (user.getUsername().equals(username) /*&& user.getPassword().equals(password)*/) {//说明该用户名已存在,必须换个用户名才能注册request.getSession().setAttribute("alert_msg", "错误:用户名已存在!");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 + "]");request.getRequestDispatcher("login.jsp").forward(request, response);} else if ("logout".equalsIgnoreCase(action)) {//登出HttpSession session = request.getSession();User user = (User) session.getAttribute("loginUser");
            vo.setUsername(username);vo.setPassword(password);//vo.setUserType("普通用户");//需要设置一个默认值userService.add(vo);request.getSession().setAttribute("alert_msg", "注册成功!用户名:[" + username + "]");request.getRequestDispatcher("login.jsp").forward(request, response);} else if ("logout".equalsIgnoreCase(action)) {//登出HttpSession session = request.getSession();User user = (User) session.getAttribute("loginUser");if (user != null) {session.removeAttribute("loginUser");}response.sendRedirect("login.jsp");} else if ("validationCode".equalsIgnoreCase(action)) {String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码//  获得验证码集合的长度int charsLength = codeChars.length();//  下面三条记录是关闭客户端浏览器的缓冲区//  这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同//  因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区response.setHeader("ragma", "No-cache");response.setHeader("Cache-Control", "no-cache");response.setDateHeader("Expires", 0);//  设置图形验证码的长和宽(图形的大小)int width = 90, height = 20;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics g = image.getGraphics();//  获得用于输出文字的Graphics对象Random random = new Random();g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色g.fillRect(0, 0, width, height);//  填充图形背景//  设置初始字体g.setFont(new Font("Times New Roman", Font.ITALIC, height));g.setColor(getRandomColor(120, 180));// 随机设置字体颜色//  用于保存最后随机生成的验证码StringBuilder validationCode = new StringBuilder();//  验证码的随机字体String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};for (int i = 0; i < 4; i++) {//  随机设置当前验证码的字符的字体g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));//  随机获得当前验证码的字符char codeChar = codeChars.charAt(random.nextInt(charsLength));validationCode.append(codeChar);//  随机设置当前验证码字符的颜色g.setColor(getRandomColor(10, 100));//  在图形上输出验证码字符,x和y都是随机生成的g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));}
            //取出表要删除的公告记录的主键long id = Long.parseLong(request.getParameter("id"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层删除方法(delete),将对应的记录删除noticeService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Notice对象的属性里Notice vo = new Notice();vo.setId(Long.valueOf(request.getParameter("id")));vo.setNoticeName(request.getParameter("noticeName"));vo.setNoticeText(request.getParameter("noticeText"));vo.setNoticeType(request.getParameter("noticeType"));vo.setCreateDate(request.getParameter("createDate"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层更新方法(update),更新记录noticeService.update(vo);this.redirectList(request, response);} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面Serializable id = request.getParameter("id");//取出页面传入的主键,用于查询详情NoticeService noticeService = new NoticeServiceImpl();Notice vo = noticeService.get(id);response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));} else {//默认去列表页面this.redirectList(request, response);}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好}/*** 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面** @param request* @param response*/private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
            salaryService.add(vo);this.redirectList(request, response);} else if ("delete".equals(action)) {//删除//取出表要删除的职工工资记录的主键long id = Long.parseLong(request.getParameter("id"));SalaryService salaryService = new SalaryServiceImpl();//调用Service层删除方法(delete),将对应的记录删除salaryService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Salary对象的属性里Salary vo = new Salary();vo.setId(Long.valueOf(request.getParameter("id")));vo.setSalaryName(request.getParameter("salaryName"));vo.setSalaryNo(request.getParameter("salaryNo"));vo.setSalaryDept(request.getParameter("salaryDept"));vo.setSalaryMoney(request.getParameter("salaryMoney"));vo.setSalaryText(request.getParameter("salaryText"));SalaryService salaryService = new SalaryServiceImpl();//调用Service层更新方法(update),更新记录salaryService.update(vo);this.redirectList(request, response);} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面Serializable id = request.getParameter("id");//取出页面传入的主键,用于查询详情SalaryService salaryService = new SalaryServiceImpl();Salary vo = salaryService.get(id);response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));} else {//默认去列表页面this.redirectList(request, response);}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        params.put("searchColumn", searchColumn);//要查询的列params.put("keyword", keyword);//查询的关键字SalaryService salaryService = new SalaryServiceImpl();Map<String, Object> map = salaryService.list(params);request.getSession().setAttribute("list", map.get("list"));Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页String pageNum = request.getParameter("pageNum");//封装分页参数com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);params.put("startIndex", pb.getStartIndex());params.put("pageSize", pb.getPageSize());List list = (List) salaryService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果listpb.setServlet("SalaryServlet");pb.setSearchColumn(searchColumn);pb.setKeyword(keyword);pb.setList(list);request.getSession().setAttribute("pageBean", pb);request.getSession().setAttribute("list", pb.getList());response.sendRedirect("salary_list.jsp");}
}/*** 公告模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>* 而后再调用NoticeService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面
            //  这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同//  因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区response.setHeader("ragma", "No-cache");response.setHeader("Cache-Control", "no-cache");response.setDateHeader("Expires", 0);//  设置图形验证码的长和宽(图形的大小)int width = 90, height = 20;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics g = image.getGraphics();//  获得用于输出文字的Graphics对象Random random = new Random();g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色g.fillRect(0, 0, width, height);//  填充图形背景//  设置初始字体g.setFont(new Font("Times New Roman", Font.ITALIC, height));g.setColor(getRandomColor(120, 180));// 随机设置字体颜色//  用于保存最后随机生成的验证码StringBuilder validationCode = new StringBuilder();//  验证码的随机字体String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};for (int i = 0; i < 4; i++) {//  随机设置当前验证码的字符的字体g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));//  随机获得当前验证码的字符char codeChar = codeChars.charAt(random.nextInt(charsLength));validationCode.append(codeChar);//  随机设置当前验证码字符的颜色g.setColor(getRandomColor(10, 100));//  在图形上输出验证码字符,x和y都是随机生成的g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));}HttpSession session = request.getSession();session.setMaxInactiveInterval(5 * 60);//  将验证码保存在session对象中,key为validation_codesession.setAttribute("validationCode", validationCode.toString());g.dispose();//  关闭Graphics对象OutputStream os = response.getOutputStream();ImageIO.write(image, "JPEG", os);// 以JPEG格式向客户端发送图形验证码} else if ("resetPassword".equalsIgnoreCase(action)) {String msg;User loginUser = (User) request.getSession().getAttribute("loginUser");String oldPassword = request.getParameter("oldPassword");if (!loginUser.getPassword().equals(oldPassword)) {msg = "原密码错误!";} else {
                UserService userService = new UserServiceImpl();userService.update(loginUser);msg = "修改成功!";}request.getSession().setAttribute("alert_msg", msg);request.getRequestDispatcher("reset_password.jsp").forward(request, response);} else {response.sendRedirect("login.jsp");}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);}// 返回一个随机颜色(Color对象)private Color getRandomColor(int minColor, int maxColor) {Random random = new Random();// 保存minColor最大不会超过255if (minColor > 255)minColor = 255;//  保存minColor最大不会超过255if (maxColor > 255)maxColor = 255;//  获得红色的随机颜色值int red = minColor + random.nextInt(maxColor - minColor);//  获得绿色的随机颜色值int green = minColor + random.nextInt(maxColor - minColor);//  获得蓝色的随机颜色值int blue = minColor + random.nextInt(maxColor - minColor);return new Color(red, green, blue);}
}
            //取出表要删除的公告记录的主键long id = Long.parseLong(request.getParameter("id"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层删除方法(delete),将对应的记录删除noticeService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Notice对象的属性里Notice vo = new Notice();vo.setId(Long.valueOf(request.getParameter("id")));vo.setNoticeName(request.getParameter("noticeName"));vo.setNoticeText(request.getParameter("noticeText"));vo.setNoticeType(request.getParameter("noticeType"));vo.setCreateDate(request.getParameter("createDate"));NoticeService noticeService = new NoticeServiceImpl();//调用Service层更新方法(update),更新记录noticeService.update(vo);this.redirectList(request, response);} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面Serializable id = request.getParameter("id");//取出页面传入的主键,用于查询详情NoticeService noticeService = new NoticeServiceImpl();Notice vo = noticeService.get(id);response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));} else {//默认去列表页面this.redirectList(request, response);}}/*** 处理Get请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好}
     * @throws ServletException* @throws IOException*/@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//过滤编码request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");String action = request.getParameter("action");if ("add".equals(action)) {//增加Zican vo = new Zican();//取出页面传进来的各个数据,并设置到Zican对象的属性里vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));vo.setZicanDate(request.getParameter("zicanDate"));vo.setZicanText(request.getParameter("zicanText"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层增加方法(add),增加记录zicanService.add(vo);this.redirectList(request, response);} else if ("delete".equals(action)) {//删除//取出表要删除的企业资产记录的主键long id = Long.parseLong(request.getParameter("id"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层删除方法(delete),将对应的记录删除zicanService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Zican对象的属性里Zican vo = new Zican();vo.setId(Long.valueOf(request.getParameter("id")));vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));vo.setZicanDate(request.getParameter("zicanDate"));vo.setZicanText(request.getParameter("zicanText"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层更新方法(update),更新记录zicanService.update(vo);
//@WebServlet("/ZicanServlet")
public class ZicanServlet extends HttpServlet {/*** 处理Post请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//过滤编码request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");String action = request.getParameter("action");if ("add".equals(action)) {//增加Zican vo = new Zican();//取出页面传进来的各个数据,并设置到Zican对象的属性里vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));vo.setZicanDate(request.getParameter("zicanDate"));vo.setZicanText(request.getParameter("zicanText"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层增加方法(add),增加记录zicanService.add(vo);this.redirectList(request, response);} else if ("delete".equals(action)) {//删除//取出表要删除的企业资产记录的主键long id = Long.parseLong(request.getParameter("id"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层删除方法(delete),将对应的记录删除zicanService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Zican对象的属性里Zican vo = new Zican();vo.setId(Long.valueOf(request.getParameter("id")));vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));
        request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");String action = request.getParameter("action");if ("add".equals(action)) {//增加Zican vo = new Zican();//取出页面传进来的各个数据,并设置到Zican对象的属性里vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));vo.setZicanDate(request.getParameter("zicanDate"));vo.setZicanText(request.getParameter("zicanText"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层增加方法(add),增加记录zicanService.add(vo);this.redirectList(request, response);} else if ("delete".equals(action)) {//删除//取出表要删除的企业资产记录的主键long id = Long.parseLong(request.getParameter("id"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层删除方法(delete),将对应的记录删除zicanService.delete(id);this.redirectList(request, response);} else if ("edit".equals(action)) {//修改//取出页面传进来的各个数据,并设置到Zican对象的属性里Zican vo = new Zican();vo.setId(Long.valueOf(request.getParameter("id")));vo.setZicanType(request.getParameter("zicanType"));vo.setZicanNo(request.getParameter("zicanNo"));vo.setZicanName(request.getParameter("zicanName"));vo.setZicanWorth(request.getParameter("zicanWorth"));vo.setZicanDate(request.getParameter("zicanDate"));vo.setZicanText(request.getParameter("zicanText"));ZicanService zicanService = new ZicanServiceImpl();//调用Service层更新方法(update),更新记录zicanService.update(vo);this.redirectList(request, response);} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面Serializable id = request.getParameter("id");//取出页面传入的主键,用于查询详情ZicanService zicanService = new ZicanServiceImpl();Zican vo = zicanService.get(id);response.getWriter().println(com.alibaba.fastjson.JSONObject.toJSONString(vo));} else {//默认去列表页面this.redirectList(request, response);}}/*** 处理Get请求** @param request* @param response* @throws ServletException
            minColor = 255;//  保存minColor最大不会超过255if (maxColor > 255)maxColor = 255;//  获得红色的随机颜色值int red = minColor + random.nextInt(maxColor - minColor);//  获得绿色的随机颜色值int green = minColor + random.nextInt(maxColor - minColor);//  获得蓝色的随机颜色值int blue = minColor + random.nextInt(maxColor - minColor);return new Color(red, green, blue);}
}/*** 项目经营模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>* 而后再调用JingyinService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面*/
//@WebServlet("/JingyinServlet")
public class JingyinServlet extends HttpServlet {/*** 处理Post请求** @param request* @param response* @throws ServletException* @throws IOException*/@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

这篇关于基于javaweb+mysql的jsp+servlet企业财务记账管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap Ajax)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/817505

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

SQL中的外键约束

外键约束用于表示两张表中的指标连接关系。外键约束的作用主要有以下三点: 1.确保子表中的某个字段(外键)只能引用父表中的有效记录2.主表中的列被删除时,子表中的关联列也会被删除3.主表中的列更新时,子表中的关联元素也会被更新 子表中的元素指向主表 以下是一个外键约束的实例展示

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

如何去写一手好SQL

MySQL性能 最大数据量 抛开数据量和并发数,谈性能都是耍流氓。MySQL没有限制单表最大记录数,它取决于操作系统对文件大小的限制。 《阿里巴巴Java开发手册》提出单表行数超过500万行或者单表容量超过2GB,才推荐分库分表。性能由综合因素决定,抛开业务复杂度,影响程度依次是硬件配置、MySQL配置、数据表设计、索引优化。500万这个值仅供参考,并非铁律。 博主曾经操作过超过4亿行数据