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

<%-- Document : a_queryNews Created on : 2016-5-18, 17:08:40 Author : Administrator --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>查询页面</title> </head> <body> <table> <tr> <td> <form action="QueryOneNews" method="post" target="_blank" > 请输入新闻编号:<input type="text"> <input type="submit" value="查询" ><br> </form> <hr></td> </tr> <tr> <td>&nbsp;</td> </tr> </table> </body> </html>

对于查询这件事,有成功,有失败,在这儿我们进行失败后文件的设置,代码如下所示,命名为a_queryNewsfailed.jsp,使用超级连接的方式,连接到主页面 

<%-- Document : a_queryNeesfailed Created on : 2016-6-6, 8:43:35 Author : Administrator --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>查询失败</title> </head> <body> <h1>没有找到你要查找的内容,但是你可以进入</h1> <a href="https://www.jb51.net/index.html">主页进行查看</a> </body> </html>

实现了以上显示层的操作之后,下面就是控制层的实现,命名为QueryOneNews.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 dao.NewsRealeseDao; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; 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 QueryOneNews extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String str_id=request.getParameter("query"); int newsid_int=Integer.valueOf(str_id); NewsRealeseDao newsRealeseDao=new NewsRealeseDao(); try { ArrayList newsRealese = newsRealeseDao.queryOneNews(newsid_int); char [] s1=newsRealese.toString().toCharArray(); System.out.println("String+newsRealese:"+newsRealese); System.out.println("String+newsRealese:"+s1[0]+" -------"+s1[1]); if(s1[0]=='['&&s1[1]==']') { response.sendRedirect("a_queryNewsfailed.jsp"); } else { response.sendRedirect("newRealese_detail.jsp?newsid="+str_id); } } 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"; } }

(9)下面实现更新数据的操作,命名为a_updateNews.jsp,其代码如下所示:

<%@page contentType="text/html" import="java.util.*,java.sql.*" pageEncoding="UTF-8" language="java"%> <%@page import="com.lut.beans.NewsRealese" %> <%@page import="dao.NewsRealeseDao" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>更改新闻-</title> <!-- 配置文件 --> <script type="text/javascript" src="https://www.jb51.net/article/ueditor/ueditor.config.js"></script> <!-- 编辑器源码文件 --> <script type="text/javascript" src="https://www.jb51.net/article/ueditor/ueditor.all.js"></script> <link type="text/css" href="https://www.jb51.net/article/udeditor/themes/default/css" /> <link type="text/css" href="https://www.jb51.net/newsRealese.css"/> </head> <body> <% NewsRealeseDao newsRealeseDao=new NewsRealeseDao(); String newsid_s=request.getParameter("newsid"); int news_int=Integer.valueOf(newsid_s); ArrayList news_list=newsRealeseDao.queryOneNews(news_int); %> <% for(int i=0;i<news_list.size();i++) { NewsRealese newRealese=(NewsRealese)news_list.get(i); %> <form action="UpdateOneNews" method="post"> <table> <tr> <td>left</td> <td> <table> <tr > <tr> <td >新闻编号</td> <td><input type="text" value="<%=newRealese.getNewsId() %>"></td> <td>所属新闻栏目编号</td> <td><input type="text" value="<%=newRealese.getClassId() %>"></td> </tr> <tr> <td>所属新闻分类编号</td> <td><input type="text" value="<%=newRealese.getKindId() %>"></td> <td>原创或转载</td> <td><input type="text" value="<%=newRealese.getMyOther() %>"></td> </tr> <tr> <td>新闻标题</td> <td><input type="text" value="<%=newRealese.getHeadTitle()%>"></td> <td>相关文章</td> <td><input type="text" value="<%=newRealese.getConnectRealtive()%>"></td> </tr> <tr> <td>作者</td> <td><input type="text" value="<%=newRealese.getAuthor() %>"></td> <td>编辑</td> <td><input type="text" value="<%=newRealese.getEditor() %>"></td> </tr> <tr> <td>出处</td> <td><input type="text" value="<%=newRealese.getNewsFrom() %>"></td> <td>是否置顶</td> <td><input type="text" value="<%=newRealese.getTop() %>"></td> </tr> <tr> <td>新闻发布时间</td> <td><input type="text" value="<%=newRealese.getNewsTime() %> "></td> <td>新闻点击次数</td> <td><input type="text" value="<%=newRealese.getHits() %>"></td> </tr> <tr> <td>新闻状态</td> <td><input type="text" value="<%=newRealese.getState() %>"></td> <td>新闻标记</td> <td><input type="text" value="<%=newRealese.getTag() %>"></td> </tr> <tr> </table> </td> <td>right</td> </tr> <tr> <td>&nbsp;</td> <td> <div> <textarea><%=newRealese.getContent() %></textarea> <br/> <input type="submit" value="发 布"> <script type="text/javascript"> UE.getEditor('newsEditor'); var content=UE.getPlainTxt();//s就是编辑器的带格式的内容 </script> </div> </td> <td>&nbsp;</td> </tr> </table> </form> <% } %> </body> </html>

在Servlet中进行如下代码所示配置:

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

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