公文流转系统③——部门功能页
作者:互联网
一、效果如下
(销售部、生产部、财务部登录后进入的均为此界面)
二、SQL语句
document表:
1 -- ---------------------------- 2 -- Table structure for `document` 3 -- ---------------------------- 4 DROP TABLE IF EXISTS `document`; 5 CREATE TABLE `document` ( 6 `id` int(11) NOT NULL AUTO_INCREMENT, 7 `title` varchar(255) DEFAULT NULL, 8 `content` varchar(255) DEFAULT NULL, 9 `time` varchar(255) DEFAULT NULL, 10 `createPeople` varchar(255) DEFAULT NULL, 11 `viceFactoryAgree` varchar(255) DEFAULT NULL, 12 `viceFactoryOpinion` varchar(255) DEFAULT NULL, 13 `factoryAgree` varchar(255) DEFAULT NULL, 14 `factoryOpinion` varchar(255) DEFAULT NULL, 15 `receiver` varchar(255) DEFAULT NULL, 16 PRIMARY KEY (`id`) 17 ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; 18 19 -- ---------------------------- 20 -- Records of document 21 -- ---------------------------- 22 INSERT INTO `document` VALUES ('3', '财务公文', '财务公文哦', '2021-09-22', 'cw', null, null, null, null, '副厂长-财务部待同意'); 23 INSERT INTO `document` VALUES ('4', '生产主分区公文1', '生产主分区公文鸭', '2021-09-22', 'scz', null, null, null, null, '副厂长-生产部待同意'); 24 INSERT INTO `document` VALUES ('5', 'xiaoshou', 'xiaoshouneirong', '2021-09-23', 'xs', null, null, null, null, '副厂长-销售部待同意'); 25 INSERT INTO `document` VALUES ('6', 'xs', 'xs', '2021-09-23', 'xs', '同意', '同意', '同意', 'tongyi', '相关部门已签收'); 26 INSERT INTO `document` VALUES ('7', 'xs3', 'nsneirong', '2021-09-23', 'xs', null, null, null, null, '副厂长-销售部待同意'); 27 INSERT INTO `document` VALUES ('8', 'cw2', 'cw222', '2021-09-23', 'cw', null, null, null, null, '副厂长-财务部待同意'); 28 INSERT INTO `document` VALUES ('9', 'cw3', 'cwneirong', '2021-09-23', 'cw', '同意', '同意鸭', null, null, '厂长待同意'); 29 INSERT INTO `document` VALUES ('10', 'sczhuchangqu', 'neirongya', '2021-09-23', 'scz', null, null, null, null, '办公室'); 30 INSERT INTO `document` VALUES ('11', '生产部一分厂哦', '公文内容鸭', '2021-09-23', 'scy', null, null, null, null, '副厂长-生产部待同意'); 31 INSERT INTO `document` VALUES ('12', 'xs2019', 'xs2019', '2021-09-23', 'xs', null, null, null, null, '办公室');
三、代码如下:
(1)department.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>部门功能页</title> 8 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 9 <script src=".//layui/layui.all.js"></script> 10 <script src=".//layui/layui.js"></script> 11 <script type="text/javascript"> 12 //JavaScript代码区域 13 layui.use('element', function() { 14 var element = layui.element; 15 }); 16 </script> 17 </head> 18 <body class="layui-layout-body"> 19 <div class="layui-layout layui-layout-admin"> 20 <div class="layui-header"> 21 <div class="layui-logo"> 22 <% 23 String department = (String) session.getAttribute("department"); 24 out.print(department); 25 %> 26 功能页欢迎 27 <% 28 String username = (String) session.getAttribute("username"); 29 out.print(username); 30 %> 31 </div> 32 <!-- 水平导航 --> 33 <ul class="layui-nav layui-layout-right"> 34 <li class="layui-nav-item "><a href="index.jsp">退出</a></li> 35 </ul> 36 </div> 37 38 <div class="layui-side layui-bg-black"> 39 <div class="layui-side-scroll"> 40 <!-- 左侧导航 --> 41 <ul class="layui-nav layui-nav-tree"> 42 <li class="layui-nav-item"><a 43 href="department_document_fiction.jsp" target="frame">公文拟制</a></li> 44 <li class="layui-nav-item"><a 45 href="DepartmentServlet?method=receipt" target="frame">签收公文</a></li> 46 <li class="layui-nav-item"><a 47 href="DepartmentServlet?method=browse" target="frame">浏览公文</a></li> 48 </ul> 49 </div> 50 </div> 51 <div class="layui-body"> 52 <!-- 内容主体区域 --> 53 <iframe name="frame" width="100%" height="100%" 54 style="border: 1px solid #CCC;"></iframe> 55 </div> 56 <div> 57 <div> 58 <input type="text" id="date" /> 59 </div> 60 </div> 61 </div> 62 </body> 63 </html>
(2)department_receipt.jsp
1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>签收公文</title> 9 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 10 <script src=".//layui/layui.all.js"></script> 11 <script src=".//layui/layui.js"></script> 12 </head> 13 <body> 14 <table class="layui-table"> 15 <thead> 16 <tr> 17 <th>id</th> 18 <th>公文标题</th> 19 <th>公文内容</th> 20 <th>时间</th> 21 <th>创建人</th> 22 <th>副厂长是否同意</th> 23 <th>副厂长意见</th> 24 <th>厂长是否同意</th> 25 <th>厂长意见</th> 26 <th>操作</th> 27 </tr> 28 </thead> 29 <tbody> 30 <c:forEach items="${list}" var="document" varStatus="status"> 31 <tr> 32 <td>${ status.index + 1}</td> 33 <td>${document.title}</td> 34 <td>${document.content}</td> 35 <td>${document.time}</td> 36 <td>${document.createPeople}</td> 37 <td>${document.viceFactoryAgree}</td> 38 <td>${document.viceFactoryOpinion}</td> 39 <td>${document.factoryAgree}</td> 40 <td>${document.factoryOpinion}</td> 41 <td><button class="layui-btn layui-btn-normal" 42 onclick="window.location.href='DepartmentServlet?method=receipt_result&title=${document.title}'">签收</button></td> 43 </tr> 44 </c:forEach> 45 </tbody> 46 </table> 47 </body> 48 </html>
(3)department_document_fiction.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>公文拟制</title> 8 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 9 <script src=".//layui/layui.all.js"></script> 10 <script src=".//layui/layui.js"></script> 11 </head> 12 <body> 13 <form class="layui-form" action="DepartmentServlet?method=document_fiction" method="post"> 14 <div class="layui-form-item"> 15 <label class="layui-form-label">公文标题</label> 16 <div class="layui-input-block"> 17 <input type="text" name="title" required lay-verify="required" 18 placeholder="请输入公文标题" autocomplete="off" class="layui-input"> 19 </div> 20 </div> 21 <div class="layui-form-item layui-form-text"> 22 <label class="layui-form-label">公文内容</label> 23 <div class="layui-input-block"> 24 <textarea name="content" placeholder="请输入公文内容" 25 class="layui-textarea"></textarea> 26 </div> 27 </div> 28 <div class="layui-form-item"> 29 <label class="layui-form-label">时间</label> 30 <div class="layui-inline"> 31 <!-- 注意:这一层元素并不是必须的 --> 32 <input type="text" class="layui-input" id="time" name="time"> 33 </div> 34 </div> 35 <div class="layui-form-item"> 36 <label class="layui-form-label">创建人</label> 37 <div class="layui-input-block"> 38 <input type="text" name="createPeople" required 39 lay-verify="required" placeholder="请输入您的账号" autocomplete="off" 40 class="layui-input"> 41 </div> 42 </div> 43 <div class="layui-form-item"> 44 <div class="layui-input-block"> 45 <button class="layui-btn" lay-submit>立即提交</button> 46 <button type="reset" class="layui-btn layui-btn-primary">重置</button> 47 </div> 48 </div> 49 </form> 50 <script> 51 layui.use('laydate', function() { 52 var laydate = layui.laydate; 53 54 //执行一个laydate实例 55 laydate.render({ 56 elem : '#time' //指定元素 57 }); 58 }); 59 </script> 60 </body> 61 </html>
(4)department_browse.jsp
1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>浏览公文</title> 9 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 10 <script src=".//layui/layui.all.js"></script> 11 <script src=".//layui/layui.js"></script> 12 </head> 13 <body> 14 <table class="layui-table"> 15 <thead> 16 <tr> 17 <th>id</th> 18 <th>公文标题</th> 19 <th>公文内容</th> 20 <th>时间</th> 21 <th>创建人</th> 22 <th>副厂长是否同意</th> 23 <th>副厂长意见</th> 24 <th>厂长是否同意</th> 25 <th>厂长意见</th> 26 </tr> 27 </thead> 28 <tbody> 29 <c:forEach items="${list}" var="document" varStatus="status"> 30 <tr> 31 <td>${ status.index + 1}</td> 32 <td>${document.title}</td> 33 <td>${document.content}</td> 34 <td>${document.time}</td> 35 <td>${document.createPeople}</td> 36 <td>${document.viceFactoryAgree}</td> 37 <td>${document.viceFactoryOpinion}</td> 38 <td>${document.factoryAgree}</td> 39 <td>${document.factoryOpinion}</td> 40 </tr> 41 </c:forEach> 42 </tbody> 43 </table> 44 </body> 45 </html>
(5)DepartmentServlet.java
1 package servlet; 2 3 import java.io.IOException; 4 import java.util.List; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 import javax.servlet.http.HttpSession; 12 13 import dao.DepartmentDao; 14 import util.Document; 15 16 /** 17 * Servlet implementation class DocumentServlet 18 */ 19 @WebServlet("/DepartmentServlet") 20 public class DepartmentServlet extends HttpServlet { 21 private static final long serialVersionUID = 1L; 22 23 /** 24 * @see HttpServlet#HttpServlet() 25 */ 26 public DepartmentServlet() { 27 super(); 28 // TODO Auto-generated constructor stub 29 } 30 31 DepartmentDao dao=new DepartmentDao(); 32 33 /** 34 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 35 */ 36 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 37 // TODO Auto-generated method stub 38 //response.getWriter().append("Served at: ").append(request.getContextPath()); 39 doPost(request,response); 40 } 41 42 /** 43 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 44 */ 45 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 46 // TODO Auto-generated method stub 47 //doGet(request, response); 48 49 request.setCharacterEncoding("utf-8"); 50 response.setCharacterEncoding("utf-8"); 51 52 System.out.println("进入DocumentServlet"); 53 String method = request.getParameter("method"); 54 System.out.println(method); 55 if("document_fiction".equals(method)) { 56 document_fiction(request,response);//创建公文 57 }else if("receipt".equals(method)) { 58 receipt(request,response);//签收公文 59 }else if("receipt_result".equals(method)) { 60 receipt_result(request,response); 61 }else if("browse".equals(method)) { 62 browse(request,response); 63 } 64 65 } 66 67 public void document_fiction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 68 response.setCharacterEncoding("UTF-8"); 69 request.setCharacterEncoding("UTF-8"); 70 71 String title = request.getParameter("title"); 72 String content = request.getParameter("content"); 73 String time = request.getParameter("time"); 74 String createPeople = request.getParameter("createPeople"); 75 System.out.println(title+","+content+","+time+","+createPeople); 76 77 Document document=new Document(title,content,time,createPeople,"办公室"); 78 79 if(dao.documentdao(document)) { 80 request.getRequestDispatcher("department_document_fiction.jsp").forward(request, response); 81 }else { 82 request.getRequestDispatcher("TestFail.jsp").forward(request, response); 83 } 84 85 } 86 public void receipt(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 87 response.setCharacterEncoding("UTF-8"); 88 request.setCharacterEncoding("UTF-8"); 89 90 System.out.println("进入receipt"); 91 92 // 使用request对象的getSession()获取session,如果session不存在则创建一个 93 HttpSession session = request.getSession(); 94 // 将数据取出 95 String name = (String) session.getAttribute("username"); 96 // 输出数据 97 System.out.println("session name;" + name); 98 99 List<Document> list=dao.receipt(name); 100 request.setAttribute("list", list); 101 request.getRequestDispatcher("department_receipt.jsp").forward(request,response); 102 103 } 104 public void receipt_result(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 105 response.setCharacterEncoding("UTF-8"); 106 request.setCharacterEncoding("UTF-8"); 107 108 String title=request.getParameter("title"); 109 110 if(dao.receipt_result(title)) { 111 request.getRequestDispatcher("DepartmentServlet?method=receipt").forward(request,response); 112 }else { 113 request.getRequestDispatcher("TestFail.jsp").forward(request,response); 114 } 115 116 } 117 public void browse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 118 response.setCharacterEncoding("UTF-8"); 119 request.setCharacterEncoding("UTF-8"); 120 121 // 使用request对象的getSession()获取session,如果session不存在则创建一个 122 HttpSession session = request.getSession(); 123 // 将数据取出 124 String name = (String) session.getAttribute("username"); 125 // 输出数据 126 System.out.println("session name;" + name); 127 128 List<Document> list=dao.browse(name); 129 request.setAttribute("list", list); 130 request.getRequestDispatcher("department_browse.jsp").forward(request,response); 131 132 } 133 134 }
(6)DepartmentDao.java
1 package dao; 2 3 import java.sql.Connection; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 import java.util.ArrayList; 7 import java.util.List; 8 9 import database.Database; 10 import util.Document; 11 12 public class DepartmentDao { 13 /** 14 * 创建公文 15 * @param document 16 * @return 17 */ 18 public boolean documentdao(Document document) { 19 Connection conn=null; 20 PreparedStatement pstm=null; 21 boolean judge=false; 22 try { 23 conn=Database.getConnection(); 24 String sql="insert into document(title,content,time,createPeople,receiver) values(?,?,?,?,?)"; 25 System.out.println(sql); 26 pstm=conn.prepareStatement(sql); 27 28 pstm.setString(1, document.getTitle()); 29 pstm.setString(2, document.getContent()); 30 pstm.setString(3, document.getTime()); 31 pstm.setString(4, document.getCreatePeople()); 32 pstm.setString(5, document.getReceiver()); 33 34 //执行插入操作 35 int num=pstm.executeUpdate(); 36 if(num>0) { 37 System.out.println("创建公文成功"); 38 judge=true; 39 }else { 40 System.out.println("创建公文失败"); 41 judge=false; 42 } 43 }catch(Exception e) { 44 e.printStackTrace(); 45 }finally { 46 //SQL执行完成后释放相关资源 47 Database.close(conn,pstm); 48 } 49 return judge; 50 } 51 /** 52 * 签收公文 53 * @return 54 */ 55 public List<Document> receipt(String name) { 56 List<Document> list = new ArrayList<>(); 57 Connection conn = null; 58 ResultSet rs = null; 59 PreparedStatement pstm = null; 60 Document document = null; 61 try { 62 conn = Database.getConnection(); 63 String sql = "select * from document where receiver=? and createPeople=?"; 64 pstm = conn.prepareStatement(sql); 65 pstm.setString(1, "部门待签收"); 66 pstm.setString(2, name); 67 rs = pstm.executeQuery(); 68 while (rs.next()) { 69 String title=rs.getString("title"); 70 String content=rs.getString("content"); 71 String time=rs.getString("time"); 72 String createPeople=rs.getString("createPeople"); 73 String viceFactoryAgree=rs.getString("viceFactoryAgree"); 74 String viceFactoryOpinion=rs.getString("viceFactoryOpinion"); 75 String factoryAgree=rs.getString("factoryAgree"); 76 String factoryOpinion=rs.getString("factoryOpinion"); 77 document=new Document(title,content,time,createPeople,viceFactoryAgree,viceFactoryOpinion,factoryAgree,factoryOpinion); 78 list.add(document); 79 } 80 } catch (Exception e) { 81 e.printStackTrace(); 82 } finally { 83 Database.close(conn, pstm, rs); 84 } 85 return list; 86 } 87 public boolean receipt_result(String title) { 88 Connection conn = null; 89 PreparedStatement pstm = null; 90 boolean judge = false; 91 String receiver="相关部门已签收"; 92 try { 93 conn = Database.getConnection(); 94 String sql = "update document set receiver=? where title=?"; 95 pstm = conn.prepareStatement(sql); 96 pstm.setString(1, receiver); 97 pstm.setString(2, title); 98 // 执行插入操作 99 int num = pstm.executeUpdate(); 100 if (num > 0) { 101 System.out.println("签收成功"); 102 judge = true; 103 } else { 104 System.out.println("签收失败"); 105 judge = false; 106 } 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } finally { 110 // SQL执行完成后释放相关资源 111 Database.close(conn, pstm); 112 } 113 return judge; 114 } 115 public List<Document> browse(String name) { 116 List<Document> list = new ArrayList<>(); 117 Connection conn = null; 118 ResultSet rs = null; 119 PreparedStatement pstm = null; 120 Document document = null; 121 try { 122 conn = Database.getConnection(); 123 String sql = "select * from document where receiver=? and createPeople=?"; 124 pstm = conn.prepareStatement(sql); 125 pstm.setString(1, "相关部门已签收"); 126 pstm.setString(2, name); 127 rs = pstm.executeQuery(); 128 while (rs.next()) { 129 String title=rs.getString("title"); 130 String content=rs.getString("content"); 131 String time=rs.getString("time"); 132 String createPeople=rs.getString("createPeople"); 133 String viceFactoryAgree=rs.getString("viceFactoryAgree"); 134 String viceFactoryOpinion=rs.getString("viceFactoryOpinion"); 135 String factoryAgree=rs.getString("factoryAgree"); 136 String factoryOpinion=rs.getString("factoryOpinion"); 137 document=new Document(title,content,time,createPeople,viceFactoryAgree,viceFactoryOpinion,factoryAgree,factoryOpinion); 138 list.add(document); 139 } 140 } catch (Exception e) { 141 e.printStackTrace(); 142 } finally { 143 Database.close(conn, pstm, rs); 144 } 145 return list; 146 } 147 }
标签:公文,功能,null,String,request,流转,document,response,pstm 来源: https://www.cnblogs.com/miao-com/p/15490022.html