新闻系统模糊查询&点击量&添加评论

目录

操作模糊查询界面index.jsp

阅读界面read.jsp

评论添加pl.jsp

                                                                                                努力学习java的小白加油 

                                                                                                                           2022.4.2


操作模糊查询界面index.jsp

<%@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">
           <h4 class="list-group-item-heading">
                <a href="${pageContext.request.contextPath}/news/read.jsp?newId=<%=rs.getInt(1) %>" data-placement="bottom" data-toggle="tooltip" href="" title="国家卫健委:昨日新增确诊病例29例,其中本土病例2例">
                    <%=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(8) %></code></span>
                <span class="glyphicon glyphicon-tag"><code><%=rs.getInt(9)%></code></span>
                <span class="glyphicon glyphicon-time"><code><%=rs.getString(5) %></code></span>
            </p>
        </li>
        
        <% 
            }
    if(con!=null&&!con.isClosed()){
  	  con.close();
    }
    if(ps!=null){
  	  ps.close();
    }
    if(rs!=null){
      rs.close();
    }
        %>
    </ul>
</div>
<div class="container text-center">
    <ul class="pagination" style="margin: 20px auto;">
        <li>
            <a href="#"><span>&laquo;</span></a>
        </li>
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
        <li><a href="#">4</a></li>
        <li><a href="#">5</a></li>
        <li>
            <a href="#"><span>&raquo;</span></a>
        </li>
    </ul>
</div>
<script>
    $(function () {
        $('[data-toggle="tooltip"]').tooltip({
            trigger: "hover"
        })
    })
</script>
</body>
</html>

阅读界面read.jsp

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="">
 
<head>
    <meta charset="UTF-8">
    <title>bootstrap</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/web04/bootstrap-3.3.7-dist/css/bootstrap.css">
    <script src="/web04/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
    <script src="/web04/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;
        }
 
        input,
        select,
        textarea,
        .panel-heading {
            border: none !important;
            border-radius: 0px !important;
        }
 
        .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.html" 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="#">新闻发布</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="${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>
     <%
      //获得新闻的id
      String newId=request.getParameter("newId");
      //根据id去数据库做查询操作
      //加载驱动
    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_id=?");
    ps.setInt(1, Integer.parseInt(newId));
    //得到结果集   
    ResultSet rs=ps.executeQuery();
    //定义需要的值
    String title="";
    int count=0;
    String author="";
    String publisher="";
    String content="";
    if(rs.next()){
    //进行赋值
    	title=rs.getString(2);
    	publisher=rs.getString(5);
    	author=rs.getString(4);
    	content=rs.getString(6);
    	count=rs.getInt(8)+1;//当前自己阅读了一次
    	}
     //已经被阅读了
     ps=con.prepareStatement("update t_news set news_count=news_count+1 where news_id=?");
     ps.setInt(1, Integer.parseInt(newId));  
     ps.executeUpdate();//不需要判断
    %>
    <div class="container" style="background: rgba(239, 231, 231, 0.9);border-radius:10px;">
        <h1><%=title %></h1>
        <h3 class="text-right">
            <small>
                <span class="glyphicon glyphicon-user"><span class="label label-default"><%=author %></span></span>
                <span class="glyphicon glyphicon-eye-open"><span class="label label-default"><%=count %></span></span>
                <span class="glyphicon glyphicon-time"><span class="label label-info"><%=publisher %></span></span>
            </small>
        </h3>
        <samp><%=content %></samp>
        <div class="btn-group btn-group-justified" style="margin-bottom: 20px;">
            <div class="btn-group">
                <a href="${pageContext.request.contextPath}/news/doDel.jsp?newId=<%=newId %>"  class="btn btn-danger">删除</a>
            </div>
            <div class="btn-group">
                <a href="${pageContext.request.contextPath}/news/upd.jsp?newId=<%=newId %>"   class="btn btn-info">修改</a>
            </div>
        </div>
    </div>
 
    <div class="container"  style="background: rgba(239, 231, 231, 0.9);border-radius:10px;margin-top: 10px;">
       <%
       
        ps=con.prepareStatement("select * from t_comment where comment_from=?");
        ps.setInt(1, Integer.parseInt(newId));
        rs=ps.executeQuery();
        while(rs.next()){
        	
       %>
        <div class="panel panel-default" style="margin-top: 20px;" >
            <div class="panel-heading">
                <span class="glyphicon glyphicon-user" ><span class="label label-success"><%=rs.getString(4) %></span></span>
                <p style="margin-top: 10px;text-indent: 2em;">
                    <samp><%=rs.getString(5) %></samp>
                </p>
                <p class="text-right">
                    <span class="glyphicon glyphicon-time"><span class="label label-info"><%=rs.getString(3) %></span></span>
                </p>
             <a href="${pageContext.request.contextPath}/news/doDelPl.jsp?newId=<%=newId %>&&id=<%=rs.getInt(1) %>"  class="btn btn-danger">删除</a>   </div>
        </div>
        
       <%
        }
       %>
 
    <form action="doAddpl.jsp" class="container" style="background: rgba(239, 231, 231, 0.9);border-radius:10px;margin-top: 10px;padding: 30px;">
        <input type="hidden" name="newId" value="<%=newId%>">
        <div class="form-group">
            <label for="">Name</label>
            <input type="text" class="form-control" name="author" placeholder="用户名称" required>
        </div>
        <div class="form-group">
            <label for="">content</label>
            <input type="text" class="form-control" name="content" placeholder="评论内容" required>
        </div>
        <button type="submit" class="btn btn-default">发布评论</button>
    </form>
 
    <div style="height: 50px;"></div>

</body></html>

评论添加pl.jsp

<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
         request.setCharacterEncoding("utf-8");
        //接收评论的数据
         String newId=request.getParameter("newId");
         String author=request.getParameter("author");
         String content=request.getParameter("content");
         String publisher=new Date().toLocaleString();
         //新闻的添加
        //加载驱动
         Class.forName("oracle.jdbc.driver.OracleDriver");
         //定义连接字符串
         String url="jdbc:oracle:thin:@localhost:1521:orcl";
        //获得连接
         Connection con=DriverManager.getConnection(url,"scott","123123");
         //主键不能不填
          //主键没有自增的选项(触发器+序列)
        //获得执行对象(数据插入之前先把id主键查询出来)
 
         PreparedStatement ps=con.prepareStatement("select nvl(max(comment_id),0) from t_comment");
         ResultSet rs=ps.executeQuery();
         int id=0;
         if(rs.next()){
        	 id=rs.getInt(1)+1;
         }
         
         //插入评论的操作
         ps=con.prepareStatement("insert into t_comment values(?,?,?,?,?)");
         //赋值
         ps.setInt(1,id);
         ps.setInt(2,Integer.parseInt(newId));
         ps.setString(3,publisher);
         ps.setString(4,author);
         ps.setString(5,content);
         
         //执行结果
         int n=ps.executeUpdate();
         if(n>0){
          //3号新闻进行评论添加
          //返回3号新闻
          
       	  out.print("<script>alert('增加成功');location.href='read.jsp?newId="+newId+"'</script>");
         }else{
       	  out.print("<script>alert('增加失败');history.go(-1)</script>");
         }
         
         if(con!=null&&!con.isClosed()){
        	  con.close();
          }
          if(ps!=null){
        	  ps.close();
          }
 

%>

                                                                                                努力学习java的小白加油 

                                                                                                                           2022.4.2

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网站是基于PHP及mysql数据库架设 网站功能介绍: 一.登陆界面 1.用户登录:网页打开出现用户登录界面,如果已拥有帐号可进行用户登录操作 2.用户注册:在没有帐号的情况下可点&#39;立即注册&#39;进入注册页面,按说明填写后便可注册成功,如果注册失败系统会提示出错的地 方 3.忘记密码:在忘记密码的情况下可根据用户名和E-MAIL地址提示用户注册时的安全问题,如正确回答问题便可找回密码 二.主页面 主页面进入后左侧显示连接,右侧页面显示最新发布的5条新闻和最新上传的5张照片,点&#39;更多&#39;便能查看全部内容,内容实现分页功能 1.新闻系统新闻分为添加和管理,添加新闻时可以添加图片,管理则可对新闻进行修改和删除,修改新闻能对其图片进行修改,并把原有图片删除 2.图片系统:图片分为添加和管理,添加图片时可以点&#39;预览&#39;,在网页下方生成该图片的预览效果,方便用户查看,管理则可对图片进行修改和删除,修改只能改图片的标题和说明,如对图片不满意就直接删除 3.留言板:基于上述两项功能又增加了留言板,其功能与上述两项大同小异,主要也是添加与管理,并具有浏览,能查看用户的留言,按用户留言的时间排序实现分页 /*上述三项功能主要实现对数据的增删改查*/ 4.投票系统:该功能主要是调查用户对本网站的满意程度,并反馈信息以便日后完善 5.友情链接:连接国内热门的门户网站,方便用户转站

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值