NewsAdd
package com.cqut.recruitPortal.servlet; import com.cqut.recruitPortal.entity.Operator; import com.cqut.recruitPortal.service.NewsService; 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.text.ParseException; import java.util.Date; /** * Servlet implementation class NewsAdd */ public class NewsAdd extends HttpServlet { private static final long serialVersionUID = 1L; NewsService service = new NewsService(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub boolean isOK = true; String title = request.getParameter("title"); String titleMessage = ""; if (title == null || title.equals("")) { isOK = false; titleMessage = "标题不能为空"; } String content = request.getParameter("content"); String contentMessage = ""; if (content == null || content.equals("")) { isOK = false; contentMessage = "内容不能为空"; } else { } String deadLine = request.getParameter("deadLine"); String deadLineMessage = ""; String type = request.getParameter("type"); String typeMessage = ""; if (type == null || type.equals("")) { typeMessage = "请选择"; } Long operatorID = ((Operator) request.getSession().getAttribute("loginOperator")).getOperatorID(); Date publishTime = new Date(); Date deadLineTime = null; if (deadLine != null && !deadLine.equals("")) { try { deadLineTime = SysUtil.praseDate(deadLine); if (deadLineTime.getTime() < publishTime.getTime()) { isOK = false; deadLineMessage = "截至时间不能小于当前时间"; } } catch (ParseException e) { isOK = false; deadLineMessage = "截至时间格式不正确,应为:2014-01-14 22:51:10"; e.printStackTrace(); } } String addMessage = ""; if (isOK) { String sql = "insert into news(`title`,`content`,`type`,`publishTime`,`deadLine`,`count`,`operator`,`status`) values(?,?,?,?,?,?,?,?)"; Object objs[] = {title, content, Long.parseLong(type), publishTime, deadLineTime, 0, operatorID, 1}; int updateCount = service.cd.executeUpdate(sql, objs); if (updateCount != 1) { addMessage = "新增失败"; } else { request.getServletContext().getRequestDispatcher("/admin/NewsServlet").forward(request, response); return; } } request.setAttribute("titleMessage", titleMessage); request.setAttribute("contentMessage", contentMessage); request.setAttribute("deadLineMessage", deadLineMessage); request.setAttribute("typeMessage", typeMessage); request.setAttribute("addMessage", addMessage); request.setAttribute("title", title); request.setAttribute("content", content); request.setAttribute("deadLine", deadLine); //request.setAttribute("title", title); String phtml = service.createOperationPermissionHtml(type, operatorID); request.setAttribute("phtml", phtml); request.getServletContext().getRequestDispatcher("/admin/newsAdd.jsp").forward(request, response); } }
NewsCanclePublish
package com.cqut.recruitPortal.servlet; import com.cqut.recruitPortal.service.NewsService; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * Servlet implementation class NewsCanclePublish */ public class NewsCanclePublish extends HttpServlet { private static final long serialVersionUID = 1L; NewsService service = new NewsService(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String newsID = request.getParameter("newsID"); //更新状态为3 String sql = "update news set status=3 where newsID=?"; service.cd.executeUpdate(sql, new Object[]{Long.parseLong(newsID)}); request.getServletContext().getRequestDispatcher("/admin/NewsServlet").forward(request, response); } }
NewsDelete
package com.cqut.recruitPortal.servlet; import com.cqut.recruitPortal.service.NewsService; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * Servlet implementation class NewsDelete */ public class NewsDelete extends HttpServlet { private static final long serialVersionUID = 1L; NewsService service = new NewsService(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String newsID = request.getParameter("newsID"); //删除 String sql = "delete from news where newsID=?"; service.cd.executeUpdate(sql, new Object[]{Long.parseLong(newsID)}); request.getServletContext().getRequestDispatcher("/admin/NewsServlet").forward(request, response); } }
NewsDetail
package com.cqut.recruitPortal.servlet; import com.cqut.recruitPortal.service.NewsService; 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.util.Date; import java.util.List; import java.util.Map; public class NewsDetail extends HttpServlet { private static final long serialVersionUID = 1L; NewsService service = new NewsService(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String newsID = request.getParameter("newsID"); //查询给定ID的 新闻 String sql = "select n.newsID AS newsID, " + "n.title AS title, " + "n.publishTime AS publishTime, " + "n.deadLine AS deadLine, " + "n.count AS count, " + "n.operator AS operator, " + "n.type AS type, " + "nt.`name` AS typeName, " + "o.`name` AS operatorName, " + "n.`content` AS content, " + "n.`status` AS status " + "from news n LEFT JOIN newstype AS nt ON n.type = nt.newsTypeID " + "LEFT JOIN operator AS o ON o.operatorID = n.operator where newsID=?"; List<Map<String, Object>> listMap = service.cd.executeQuery(sql, new Object[]{Long.parseLong(newsID)}); if (listMap.size() == 1) { Map<String, Object> news = listMap.get(0); if (news.get("publishTime") != null) { news.put("publishTime", SysUtil.formatDate((Date) news.get("publishTime"))); } if (news.get("deadLine") != null) { news.put("deadLine", SysUtil.formatDate((Date) news.get("deadLine"))); } //为了在jsp页面上有格式我们需要做一定的处理 String content = news.get("content").toString(); content = content.replaceAll(" ", " "); content = content.replaceAll("\t", " "); content = content.replaceAll("\r\n", "<br/>"); news.put("content", content); request.setAttribute("news", news); } request.getServletContext().getRequestDispatcher("/admin/newsDetail.jsp").forward(request, response); } }
NewsEdit
package com.cqut.recruitPortal.servlet; import com.cqut.recruitPortal.entity.Operator; import com.cqut.recruitPortal.service.NewsService; 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.text.ParseException; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * Servlet implementation class NewsEdit */ public class NewsEdit extends HttpServlet { private static final long serialVersionUID = 1L; NewsService service = new NewsService(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub boolean isOK = true; String newsID = request.getParameter("newsID"); String title = request.getParameter("title"); String titleMessage = ""; if (title == null || title.equals("")) { isOK = false; titleMessage = "标题不能为空"; } String content = request.getParameter("content"); String contentMessage = ""; if (content == null || content.equals("")) { isOK = false; contentMessage = "内容不能为空"; } String type = request.getParameter("type"); String typeMessage = ""; if (type == null || type.equals("")) { typeMessage = "请选择"; } Long operatorID = ((Operator) request.getSession().getAttribute("loginOperator")).getOperatorID(); Date publishTime = new Date(); Date deadLineTime = null; String deadLine = request.getParameter("deadLine"); String deadLineMessage = ""; if (deadLine != null && !deadLine.equals("")) { try { deadLineTime = SysUtil.praseDate(deadLine); if (deadLineTime.getTime() < publishTime.getTime()) { isOK = false; deadLineMessage = "截至时间不能小于当前时间"; } } catch (ParseException e) { isOK = false; deadLineMessage = "截至时间格式不正确,应为:2014-01-14 22:51:10"; e.printStackTrace(); } } String addMessage = ""; if (isOK) { String updateSql = "update news set `title`=?, `content`=?, `type`=?, `deadLine`=? where newsID=?"; Object objs[] = {title, content, Long.parseLong(type), deadLineTime, Long.parseLong(newsID)}; int updateCount = service.cd.executeUpdate(updateSql, objs); if (updateCount != 1) { addMessage = "编辑失败"; } else { request.getServletContext().getRequestDispatcher("/admin/NewsServlet").forward(request, response); return; } } request.setAttribute("titleMessage", titleMessage); request.setAttribute("contentMessage", contentMessage); request.setAttribute("deadLineMessage", deadLineMessage); request.setAttribute("typeMessage", typeMessage); request.setAttribute("addMessage", addMessage); Map<String, Object> map = new HashMap<String, Object>(); map.put("title", title); map.put("content", content); map.put("deadLine", deadLine); map.put("newsID", newsID); request.setAttribute("news", map); //request.setAttribute("title", title); String phtml = service.createOperationPermissionHtml(type, operatorID); request.setAttribute("phtml", phtml); request.getServletContext().getRequestDispatcher("/admin/newsEdit.jsp").forward(request, response); } }
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>后台管理</title> <style type="text/css"> body { margin: 0; } /*下面的 css 用于框架的布局*/ .content { position: absolute; top: 87px; left: 0; bottom: 0; right: 0; } .left { position: absolute; left: 5px; width: 190px; bottom: 5px; top: 5px; overflow-x: hidden; overflow-y: auto; border: 1px solid #e5e5e5; } .right { position: absolute; left: 202px; top: 5px; right: 5px; bottom: 5px; border: 1px solid #e5e5e5; } /*设置Iframe的样式*/ .innerFrame { border: 0; position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; } </style> </head> <body> <!-- ${loginOperator.name} 这样的代码叫做EL表达式 --> <div> <table width="100%" bgcolor="#383838"> <tr> <td width="80%"> <img alt="" src="image/ll.png"> </td> <td width="20%" valign="middle"> <div style="height: 32px;line-height: 32px; min-width: 50px;float: left;"> <font color="#ffffff">欢迎 ${loginOperator.name}          </font> </div> <a href="admin/AdminLogout"><img alt="" src="image/exit.png"></a> </td> </tr> </table> <div class="content"> <div class="left"> <!-- 系统管理员 --> <c:if test="${loginOperator.type==1}"> <p> <a href="admin/OperatorServlet" target="innerFrame">用户管理</a></p> <p> <a href="admin/OperatorTypeServlet" target="innerFrame">用户类型管理</a></p> <p> <a href="admin/NewsTypeServlet" target="innerFrame">新闻类型管理</a></p> <p> <a href="admin/PermissionServlet" target="innerFrame">权限分配</a></p> </c:if> <!-- 管理员 --> <c:if test="${loginOperator.type==2}"> <p> <a href="admin/NewsServlet" target="innerFrame">新闻管理</a></p> </c:if> </div> <div class="right"> <iframe src="admin/welcome.jsp" class="innerFrame" name="innerFrame" frameborder="0" scrolling="auto" style="margin: 0px auto; height: 100%; -ms-overflow-x: hidden;"></iframe> </div> </div> </div> </body> </html>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录</title> <link href="css/page.css" rel="stylesheet"/> <link href="css/common.css" rel="stylesheet"/> <style type="text/css"> /*为了降低初学的难度,我尽量的不用 css,javascript 。但是 我也会引入一些(毕竟做web,写网站离不开这些东西),在引入的地点我都有详细的说明*/ .loginform { /*这是css。这段代码的作用是让 class属性为 loginform 的 元素水平垂直居中。很经典的代码 */ position: absolute; width: 400px; height: 250px; top: 50%; left: 50%; margin-top: -125px; margin-left: -200px; /*设置边框*/ border: 1px solid #8a8a8a; } /*给页面设置背景颜色*/ body { background-color: #e5e5e5; } </style> </head> <body> <a href="#">前台首页</a> <hr/> <div class="loginform"> <form action="admin/AdminLogin" method="post"> <br> <p class="logintitle"> 管理员登录</font></p> <br> <label for="accountField">登录帐号:</label> <input type="text" name="account" value="${account}" id="accountField"/> <font color="red">${accountMessage}</font><br><br> <label for="passwordField">登录密码:</label> <input type="password" name="password" id="passwordField"/> <font color="red">${passwordMessage}</font><br><br> <input type="submit" value="登录"/> </form> </div> </body> </html>
newsList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>新闻列表</title> <link href="css/page.css" rel="stylesheet"/> <link href="css/common.css" rel="stylesheet"/> </head> <body> <table width="100%"> <tr> <td width="50%" align="left" valign="middle"> 当前位置:<a href="admin/NewsServlet">新闻管理</a> </td> <td align="right"> <a href="admin/NewsInitAdd">新增</a> </td> </tr> </table> <hr> <form action="admin/NewsServlet" method="post"> <p> 新闻标题:<input type="text" name="querytitle" value="${querytitle}"/> <input type="submit" value="查询"/> </p> </form> <table width="100%" class="dataTable"> <thead> <tr class="title"> <td>新闻标题</td> <td width="100">类型</td> <td width="100" align="center">发布时间</td> <td width="100" align="center">截至时间</td> <td width="90" align="center">发布人</td> <td width="90" align="right">浏览次数</td> <td width="90" align="center">状态</td> <td width="270">操作</td> </tr> </thead> <tbody> <c:forEach items="${list}" var="item"> <tr> <td>${item.title}</td> <td>${item.typeName}</td> <td align="center">${item.publishTime}</td> <td align="center">${item.deadLine }</td> <td align="center">${item.operatorName}</td> <td align="right">${item.count}</td> <td align="center">${item.status}</td> <td>${item.operate}</td> </tr> </c:forEach> </tbody> </table> <c:if test="${not empty paginationHtml}"> <div class="page">${paginationHtml}</div> </c:if> </body> </html>
四、其他
1.其他系统实现
1.JavaWeb系统系列实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现学生信息管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现学生成绩管理系统-1
Java+Servlet+JSP实现学生成绩管理系统-2
Java+Servlet+JSP实现宠物诊所管理系统
Java+SSM+Easyui实现网上考试系统
Java+SSH+Bootstrap实现在线考试系统(含论文)
Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统
2.JavaSwing系统系列实现
Java+Swing实现斗地主游戏
Java+Swing实现图书管理系统
Java+Swing实现医院管理系统
Java+Swing实现仓库管理系统-1
Java+Swing实现仓库管理系统-2
Java+Swing实现考试管理系统
Java+Swing实现自助取款机系统
Java+Swing实现通讯录管理系统
Java+Swing实现停车场管理系统
Java+Swing实现学生信息管理系统
Java+Swing实现学生宿舍管理系统
Java+Swing实现学生选课管理系统
Java+Swing实现学生成绩管理系统
Java+Swing实现学校教材管理系统
Java+Swing实现学校教务管理系统
Java+Swing实现企业人事管理系统
Java+Swing实现电子相册管理系统
Java+Swing实现超市管理系统-TXT存储数据
Java+Swing实现自助取款机系统-TXT存储数据
Java+Swing实现宠物商店管理系统-TXT存储数据