基于jsp实现新闻管理系统 附完整源码(6)

在登录的过程中,我们需要进行判断,命名为checkLogin.java,,通过此类进行判断登录是否成功,若成功,则跳转到管理界面,若失败,则停留在当前界面,其代码如下所示: 

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package servlet; import com.lut.beans.NewsRealese; import dao.NewsRealeseDao; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class checkLogin extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String user=request.getParameter("user"); String pass=request.getParameter("pass"); NewsRealeseDao newsRealeseDao=new NewsRealeseDao(); try { String newsRealese=newsRealeseDao.ischecked(user,pass); if(newsRealese!=null) { response.sendRedirect("adminManager.jsp"); } else { response.sendRedirect("https://www.jb51.net/adminLogin.jsp"); } } catch (Exception ex) { Logger.getLogger(checkLogin.class.getName()).log(Level.SEVERE, null, ex); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"+"public String getServletInfo() "; }// </editor-fold> }

(5)管理员登陆之后的界面,命名为adminManager.jsp页面,在管理员界面能够进行删除修改增加和查询操作,其代码如下所示:

<%-- Document : adminManager Created on : 2016-5-18, 17:10:01 Author : Administrator --%> <%@page import="java.util.ArrayList"%> <%@page import="com.lut.beans.NewsRealese"%> <%@page import="dao.NewsRealeseDao"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>管理员界面||adminManager.jsp</title> <link type="text/css" href="https://www.jb51.net/newsRealese.css"/> </head> <body> <h1>新闻管理</h1><br> <table> <tr> <td> <table > <tr> <td><div>新闻信息显示 </div></td> </tr> <tr> <td><img src="https://www.jb51.net/article/images/dog.jpg"></td> </tr> <tr> <td><img src="https://www.jb51.net/article/images/minus.gif" ></td> </tr> </table></td> <td> <table> <tr> <td> <% NewsRealeseDao newsRealeseDao = new NewsRealeseDao(); ArrayList newsRealese = newsRealeseDao.queryAllNews(); %> <% for (int i = 0; i < newsRealese.size(); i++) { NewsRealese newRealese = (NewsRealese) newsRealese.get(i); %> <table> <tr> <td><p>此处假设无图片</p> <p>此处假设无等级信息</p> </td> <td ><table> <tr> <td >原创或转载:</td> <td ><%=newRealese.getMyOther()%> </td> <td >新闻标题:</td> <td ><%=newRealese.getHeadTitle()%> </td> </tr> <tr> <td colspan="6">新闻内容:</td> </table> <table> <tr> <td> <a target="_blank" href="newRealese_detail.jsp?newsid=<%=newRealese.getNewsId()%>"/> <table> <tr> <td> <%=newRealese.getContent()%> </td> </tr> </table> </td> </tr> </table> <table> <tr> <td>作者:</td> <td><%=newRealese.getAuthor()%> </td> <td>新闻发布时间:</td> <td><%=newRealese.getNewsTime()%> </td> <td>新闻点击次数:</td> <td><%=newRealese.getHits()%> </td> </tr> </table></td> </tr> <tr> <td colspan="2"> <input type="button" value="删除"> <input type="button" value="修改"> <hr> </td> </tr> </table> <% } %> </td> </tr> </table> </td> <td> <%@include file="a_queryNews.jsp" %> </td> </tr> <tr> <td><a href="https://www.jb51.net/a_addNews.jsp" target="_blank">添加新闻</a></td> <td>二</td> <td>三</td> </tr> </table> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjsdd.html