Java Web新闻发布系统03(功能完善)

本文介绍了Java Web新闻发布系统的功能完善,包括标题模糊查询、阅读界面的改进(点击量统计、评论添加与删除)、页面标题分类以及数据库评论表的建立。通过这些功能,提升了用户体验并加强了系统管理。
摘要由CSDN通过智能技术生成

主要完成的功能:

一、完成标题模糊查询

 二、阅读界面的完善

1、完成点击量

 2.完成评论添加

 3.完成评论删除

三、完成页面标题分类

四、数据库的建立

评论表:


一、完成标题模糊查询

一般情况下我们可能需要查看某一类新闻,或者网上购物时在搜索框中输入自己所需的物品的关键字来查找物品,这个功能就是我们程序员所说的模糊查询功能!!下面我们来看一下该功能实现的代码吧。

根据输入的标题关键字进行模糊查询(例如:输入“疫情”则出现如下新闻)

 模糊查询是在首页进行操作 代码在首页代码里面:

<%@page import="java.nio.charset.StandardCharsets"%>
<%@page import="sun.nio.cs.UTF_8"%>
<%@page import="sun.nio.cs.UTF_8"%>
<%@page import="sun.nio.cs.UTF_8"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@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="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="/web04/news/add.jsp">新闻发布</a></li>
                    <li class="divider"></li>
                    <li><a href="/web04/news/show.jsp">类别管理</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a><%=request.getParameter("yh") %></a></li>
            <li><a href="${pageContext.request.contextPath}/login.jsp">退出<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: 0px 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">
    <% 
    //点击了表单之后 跳转的是当前这个页面 同时携带一个newName(查询的关键字)过来
    String newName=request.getParameter("newName");
    if(newName==null){
    	newName="";//查询所有
    }
    //破碎重组
    //newName=new String(newName.getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
    //加载驱动
    Class.forName("oracle.jdbc.driver.OracleDriver");
    //定义连接字符串
    String url="jdbc:oracle:thin:@localhost:1521:orcl";
    //获得连接
    Connection con=DriverManager.getConnection(url,"scott","123123");
    //获得执行对象(查询所有的新闻数据)
    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">
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值