JavaWeb.05.新闻系统功能制作(增删改查)

容易出bug的新闻小项目~


目录:

        常见报错的点?

        数据库(Oracle)的建表语句

        功能介绍:

        首页数据的显示:

        新闻阅读界面(查看):

        新闻增加:

        新闻修改:

        新闻删除:


常见报错的点?

在form表单中,常出现【请求头太大】的错误,那么出错的点应该是method属性下的get属性,所以我们应该将 method:get  修改为 method:post

补充

之前我们一般都会使用 静态的【定死的】:/web05/news/index.jsp

但是之后我们要灵活使用 动态的【跟着项目名称改变的】:

$ {pageContext.request.contextPath}/news/index.jsp

因此我们可以划重点:$ {pageContext.request.contextPath}  取项目名称

回顾新闻增加功能:

新闻的主键不会自增:

                1.使用触发器+序列

                2.插入之前先取出的id+1


数据库(Oracle)的建表语句

create table t_topic
(--新闻话题表
    topic_id   number primary key,
    topic_name varchar2(20) not null
);

create table t_news
(--新闻表
    news_id        number primary key,
    news_title     varchar2(255) not null,
    news_topic     number        not null,
    news_author    varchar2(255) not null,
    news_publisher varchar2(255) not null,
    news_content   long          not null,
    news_cover     varchar2(255)
);

create table t_comment
(--评论表
    comment_id        number primary key,
    comment_from      number        not null,
    comment_publisher varchar2(20)  not null,
    comment_author    varchar2(20)  not null,
    comment_content   varchar2(255) not null
);

create table t_user

(--用户表
       user_id number primary key,
       user_name varchar(20) not null,
       user_pwd varchar(20) not null
);


  功能介绍:

  首页数据的显示:在首页查看所有已发布的新闻

  主页 index.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="zh">

<head>
    <meta charset="UTF-8">
    <title>bootstrap</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link href="/web04/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <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;
        }

        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.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="/web04/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 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 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">
	<%
	//加载驱动
		Class.forName("oracle.jdbc.driver.OracleDriver");
		//定义连接字符串
		String url="jdbc:oracle:thin:@localhost:1521:orcl";
		//获得连接
		Connection con=DriverManager.getConnection(url,"scott","123");
		//查询所有的新闻数据
		PreparedStatement ps=con.prepareStatement("select * from t_news02");
		//得到结果集
		ResultSet rs=ps.executeQuery();
		//结果集中有很多数据
		while(rs.next()){
	
	%>
    
        <li class="list-group-item">
            <h4 class="list-group-item-heading">
                <a href="${pageCo
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值