JavaWeb.06.新闻系统功能制作

这篇博客主要讲述了如何完善JavaWeb新闻系统的功能,包括新闻的模糊查询、评论的发表与处理、评论的显示以及主体内容的展示,通过代码分析帮助理解实现细节。
摘要由CSDN通过智能技术生成

上一篇也是放了新闻项目的代码,但是还有许多功能还没有完善,今天就完善一下功能代码吧
一.模糊查询
根据新闻名字(newName)

<%@page import="java.nio.charset.StandardCharsets"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh">
 
<head>
    <meta charset="UTF-8">
    <title>bootstrap</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link href="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <style>
        * {
   
            outline: none !important;
        }
 
        body,
        html {
   
            background: #7f8d90;
        }
 
        nav,
        .breadcrumb {
   
            border-radius: 0px !important;
            margin-bottom: 0px !important;
        }
 
        .breadcrumb {
   
            margin-bottom: 20px !important;
            background: #36485c;
            color: white;
        }
 
        li h4 {
   
            width: 300px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
 
        .breadcrumb .active {
   
            color: yellow;
        }
    </style>
</head>
 
<body>
<nav class="navbar navbar-default hidden-sm hidden-xs">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="${pageContext.request.contextPath}/news/index.jsp"
               style="font-size: 25px;"></a>
        </div>
        <ul class="nav navbar-nav">
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown"> 新闻管理
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="${pageContext.request.contextPath}/news/add.jsp">新闻发布</a></li>
                    <li class="divider"></li>
                    <li><a href="#">类别管理</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a><%=request.getParameter("yh") %>
            </a></li>
            <li><a href="#">退出<span class="glyphicon glyphicon-off"></span></a></li>
        </ul>
    </div>
</nav>
 
<ol class="breadcrumb">
    <li>您当前的位置是</li>
    <li>新闻发布系统</li>
    <li class="active">首页</li>
</ol>
 
<form action="${pageContext.request.contextPath}/news/index.jsp" class="form-inline" style="margin: 0 auto 20px;" >
    <div class="form-group" style="display: block;text-align: center;">
        <div class="input-group">
            <div class="input-group-addon">新闻标题</div>
            <input name="newName" class="form-control" placeholder="请在此输入搜索的关键字" type="text">
            <span class="input-group-btn">
                    <button class="btn btn-primary" type="submit">搜索🔍</button>
                </span>
        </div>
    </div>
</form>
 
<div class="container">
    <ul class="list-group">
        <%
           
            //点击表单后,跳转当前页面同时携带查询关键字
            String newName=request.getParameter("newName");
            if(newName==null){
   
            	newName="";//查询所有
            }
        
           //加载驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //定义连接字符串
            String url = "jdbc:oracle:thin:@localhost:1521:orcl";
            //获得连接
            Connection con = DriverManager.getConnection(url, "scott", "sa123");
            //查询所有的新闻数据
            PreparedStatement ps = con.prepareStatement("select * from t_news where news_title like ?");
            //设置占位符
            ps.setString(1, "%"+newName+"%");
            //得到结果集
            ResultSet rs = ps.executeQuery();
            //结果集中有很多数据
            while (rs.next()) {
   
        %>
        
        <li class="list-group-item">
            <h4 class="list-group-item-heading">
                <a href="${pageContext.request.contextPath}/news/read.jsp?newId=<%=rs.getInt(1)%>" data-placement="bottom" data-toggle="tooltip" >
                    <%=rs.getString(2)%>
                </a>
            </h4>
            <p class="list-group-item-text text-right">
                <span class="glyphicon glyphicon-user"><code><%=rs.getString(4)%></code></span>
                <span class="glyphicon glyphicon-eye-open"><code><%=rs.getInt(7)%></code></span>
                <span class="glyphicon glyphicon-tag"><code>
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值