1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Bootstrap4+MySQL前后端综合实训-Day08-PM【ajax获取表单标签内容 根据“栏目信息”

Bootstrap4+MySQL前后端综合实训-Day08-PM【ajax获取表单标签内容 根据“栏目信息”

时间:2022-01-29 11:49:56

相关推荐

Bootstrap4+MySQL前后端综合实训-Day08-PM【ajax获取表单标签内容 根据“栏目信息”

【Bootstrap4前端框架+MySQL数据库】前后端综合实训【10天课程 博客汇总表 详细笔记】【附:实训所有代码】

目 录

ajax获取表单标签内容

ajax根据数据库加载select下来列表框的options

根据“栏目信息”添加“新闻信息”

news_manager.html

AddNewsServlet.java

新闻管理系统后台数据(SQL语句)

eclipse导入Web项目代码报错解决方案

新闻管理系统——项目展示

“新闻管理”栏目

ajax获取表单标签内容

ajax根据数据库加载select下来列表框的options

根据“栏目信息”添加“新闻信息”

报错信息:Cannotaddorupdateachildrow:aforeignkeyconstraintfails(`zykkk`.`news_info`,CONSTRAINT`FK_Reference_4`FOREIGNKEY(`item_id`)REFERENCES`new_item`(`item_id`))

news_manager.html

AddNewsServlet.java

package com.newcapec.servlet.news;import java.io.IOException;import java.sql.SQLException;import java.util.HashMap;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.alibaba.fastjson.JSON;import com.newcapec.dao.NewsInfoDao;import com.newcapec.entity.NewsInfoEntity;/*** Servlet implementation class AddNewsServlet*/@WebServlet(name = "/AddNewsServlet", urlPatterns = "/AddNewsServlet")public class AddNewsServlet extends HttpServlet {private static final long serialVersionUID = 1L;private NewsInfoDao newsInfoDao = new NewsInfoDao();/*** @see HttpServlet#HttpServlet()*/public AddNewsServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse*response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().append("Served at: ").append(request.getContextPath());}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse*response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// TODO Auto-generated method stub// doGet(request, response);request.setCharacterEncoding("utf-8");response.setContentType("text/json;charset=utf-8");String addNewsTitle = request.getParameter("addNewsTitle");String addNewsItem = request.getParameter("addNewsItem"); // 栏目idString addNewsContent = request.getParameter("addNewsContent");NewsInfoEntity newsInfoEntity = new NewsInfoEntity();newsInfoEntity.setNewsTitle(addNewsTitle);newsInfoEntity.setItemId(Integer.parseInt(addNewsItem));newsInfoEntity.setNewsContent(addNewsContent);try {boolean flag = newsInfoDao.insert(newsInfoEntity);HashMap<String, Boolean> result = new HashMap<>();result.put("flag", flag);response.getWriter().write(JSON.toJSONString(result));} catch (ClassNotFoundException | SQLException e) {// TODO 自动生成的 catch 块e.printStackTrace();}}}

新闻管理系统后台数据(SQL语句)

/*SQLyog Ultimate v12.08 (64 bit)MySQL - 8.0.20 : Database - zykkk**********************************************************************//*!40101 SET NAMES utf8 */;/*!40101 SET SQL_MODE=''*/;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;CREATE DATABASE /*!32312 IF NOT EXISTS*/`zykkk` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;USE `zykkk`;/*Table structure for table `item_user` */DROP TABLE IF EXISTS `item_user`;CREATE TABLE `item_user` (`item_user_id` int NOT NULL AUTO_INCREMENT,`user_id` int DEFAULT NULL,`item_id` int DEFAULT NULL,`create_time` datetime DEFAULT NULL COMMENT '创建时间',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',`status` int DEFAULT '1' COMMENT '1:启用 0:禁用',PRIMARY KEY (`item_user_id`),KEY `FK_Reference_2` (`user_id`),KEY `FK_Reference_3` (`item_id`),CONSTRAINT `FK_Reference_2` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`),CONSTRAINT `FK_Reference_3` FOREIGN KEY (`item_id`) REFERENCES `new_item` (`item_id`)) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;/*Data for the table `item_user` */insert into `item_user`(`item_user_id`,`user_id`,`item_id`,`create_time`,`update_time`,`status`) values (1,1,2,'-11-23 11:24:16','-11-25 10:27:54',1),(2,2,4,NULL,'-11-25 09:38:17',1),(3,1,1,'-11-24 09:19:58','-11-25 09:38:21',1),(5,1,18,NULL,'-11-25 09:44:16',1),(6,1,27,'-11-25 11:11:35','-11-25 11:11:35',1),(7,1,28,'-11-25 11:17:59','-11-25 11:17:59',1),(8,1,29,'-11-25 11:29:14','-11-25 11:29:14',1),(9,1,30,'-11-25 11:30:54','-11-25 11:30:54',1),(10,1,31,'-11-25 11:36:51','-11-25 11:36:51',1),(11,1,32,'-11-25 16:26:23','-11-25 16:26:23',1),(12,1,33,'-11-25 16:26:37','-11-25 16:26:37',1);/*Table structure for table `logs_info` */DROP TABLE IF EXISTS `logs_info`;CREATE TABLE `logs_info` (`logs_id` int NOT NULL AUTO_INCREMENT,`user_id` int DEFAULT NULL,`logs_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci,`create_time` datetime DEFAULT NULL COMMENT '创建时间',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',PRIMARY KEY (`logs_id`),KEY `FK_Reference_1` (`user_id`),CONSTRAINT `FK_Reference_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`)) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;/*Data for the table `logs_info` */insert into `logs_info`(`logs_id`,`user_id`,`logs_content`,`create_time`,`update_time`) values (1,1,NULL,NULL,'-11-24 09:27:05'),(2,2,NULL,NULL,'-11-24 09:27:12'),(3,4,NULL,NULL,'-11-23 11:29:06'),(14,1,'woshishenren','-11-24 09:24:52','-11-24 09:24:52'),(15,1,'woshishenren','-11-24 09:25:58','-11-24 09:25:58');/*Table structure for table `new_item` */DROP TABLE IF EXISTS `new_item`;CREATE TABLE `new_item` (`item_id` int NOT NULL AUTO_INCREMENT,`item_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,`create_time` datetime DEFAULT NULL COMMENT '创建时间',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',`status` int DEFAULT '1' COMMENT '1:启用 0:禁用',PRIMARY KEY (`item_id`)) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;/*Data for the table `new_item` */insert into `new_item`(`item_id`,`item_name`,`create_time`,`update_time`,`status`) values (1,'学生会','-11-24 15:47:00','-11-25 14:44:37',1),(2,'党支部','-11-24 15:47:03','-11-25 14:44:31',0),(3,'分团委','-11-24 15:47:05','-11-25 14:43:54',1),(4,'院团委','-11-24 15:47:08','-11-25 14:44:38',1),(5,'111','-11-23 15:22:54','-11-25 14:45:55',1),(6,'学生会','-11-24 09:27:36','-11-25 14:46:01',1),(8,'党支部','-11-24 13:51:13','-11-25 14:46:07',1),(18,'党支部','-11-25 09:11:51','-11-25 15:49:06',1),(19,'院团委','-11-25 10:42:54','-11-25 14:46:16',1),(20,'111','-11-25 10:54:12','-11-25 14:46:19',1),(21,'学生会','-11-25 10:56:21','-11-25 14:46:35',1),(22,'党支部','-11-25 10:57:35','-11-25 14:46:43',1),(23,'分团委','-11-25 11:00:20','-11-25 14:46:48',1),(24,'院团委','-11-25 11:00:47','-11-25 14:46:55',1),(25,'qweqwe','-11-25 11:01:37','-11-25 11:01:37',1),(26,'eqweqweqwe','-11-25 11:01:53','-11-25 11:01:53',1),(27,'分团委','-11-25 11:11:35','-11-25 15:49:18',1),(28,'sadsads','-11-25 11:17:59','-11-25 11:18:40',0),(29,'院团委','-11-25 11:29:13','-11-25 15:49:25',1),(30,'789','-11-25 11:30:54','-11-25 11:37:19',0),(31,'zyk','-11-25 11:36:51','-11-25 11:37:19',0),(32,'琨家军委员会','-11-25 16:26:23','-11-25 16:26:30',0),(33,'委员会','-11-25 16:26:37','-11-25 22:42:25',1);/*Table structure for table `news_info` */DROP TABLE IF EXISTS `news_info`;CREATE TABLE `news_info` (`new_id` int NOT NULL AUTO_INCREMENT,`item_id` int DEFAULT NULL,`news_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,`news_image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci DEFAULT NULL,`news_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci,`create_time` datetime DEFAULT NULL COMMENT '创建时间',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',PRIMARY KEY (`new_id`),KEY `FK_Reference_4` (`item_id`),CONSTRAINT `FK_Reference_4` FOREIGN KEY (`item_id`) REFERENCES `new_item` (`item_id`)) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;/*Data for the table `news_info` */insert into `news_info`(`new_id`,`item_id`,`news_title`,`news_image`,`news_content`,`create_time`,`update_time`) values (1,2,'蓝桥杯比赛',NULL,NULL,NULL,'-11-23 09:27:39'),(2,3,'新学期学费',NULL,NULL,NULL,'-11-23 09:28:10'),(3,1,'拔河比赛',NULL,'拔河比赛要使劲!!!','-11-25 14:57:28','-11-25 14:57:32'),(4,18,'街舞比赛',NULL,'一起摇摆~','-11-25 15:54:09','-11-25 15:54:11'),(10,27,'数学建模',NULL,'一起加油!','-11-25 16:10:02','-11-25 22:17:19'),(11,29,'班班唱',NULL,'《走向复兴》','-11-25 16:12:23','-11-25 16:12:23'),(12,1,'篮球比赛',NULL,'冲冲冲~','-11-25 16:13:04','-11-25 16:13:04'),(13,1,'大英竞赛NECCS',NULL,'冲呀~','-11-25 16:27:22','-11-25 22:17:45'),(14,18,'卓见杯',NULL,'啦啦啦~','-11-25 17:41:32','-11-25 22:17:56');/*Table structure for table `user_info` */DROP TABLE IF EXISTS `user_info`;CREATE TABLE `user_info` (`user_id` int NOT NULL AUTO_INCREMENT,`user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,`user_pwd` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,`create_time` datetime DEFAULT NULL COMMENT '创建时间',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',`status` int DEFAULT '1' COMMENT '1:启用 0:禁用',PRIMARY KEY (`user_id`)) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;/*Data for the table `user_info` */insert into `user_info`(`user_id`,`user_name`,`user_pwd`,`create_time`,`update_time`,`status`) values (1,'宋书航','1','-11-23 09:30:16','-11-25 22:16:25',1),(2,'雨柔子','1','-11-23 11:25:41','-11-25 22:16:25',1),(4,'王五','1','-11-23 11:25:58','-11-25 22:16:26',0),(5,'赵柳','1','-11-23 11:26:12','-11-25 22:16:26',0),(8,'田七','1','-11-23 11:26:29','-11-25 22:16:27',0),(9,'田七','1','-11-23 15:03:23','-11-25 22:16:28',0),(10,'田七','1','-11-23 15:03:43','-11-25 22:16:28',0),(11,'戴沐白','1','-11-24 10:45:06','-11-25 22:16:29',1),(12,'张小凡','1','-11-24 10:45:29','-11-25 22:16:29',1),(13,'userName2','1','-11-24 10:45:29','-11-25 22:16:30',0),(14,'userName3','1','-11-24 10:45:29','-11-25 22:16:30',0),(15,'碧瑶','1','-11-24 10:45:29','-11-25 22:16:31',1),(16,'赵恋凡','1','-11-24 10:45:29','-11-25 22:16:31',1),(17,'李长寿','1','-11-24 10:45:29','-11-25 22:16:32',1),(18,'蓝梦娥','1','-11-24 10:45:29','-11-25 22:16:33',1),(19,'userName8','1','-11-24 10:45:29','-11-25 22:16:38',0),(20,'userName9','123456','-11-24 10:45:29','-11-25 11:36:31',0),(21,'userName10','123456','-11-24 10:45:29','-11-25 11:36:36',0),(22,'路明非','123456','-11-24 10:45:29','-11-25 17:44:31',1),(23,'楚子航','123456','-11-24 10:45:29','-11-25 22:14:26',1),(24,'userName13','123456','-11-24 10:45:29','-11-24 10:45:29',1),(25,'userName14','123456','-11-24 10:45:29','-11-24 10:45:29',1),(26,'userName15','123456','-11-24 10:45:29','-11-25 23:03:54',0),(27,'userName16','123456','-11-24 10:45:29','-11-25 23:03:54',0),(28,'userName17','123456','-11-24 10:45:29','-11-25 23:03:54',0),(29,'userName18','123456','-11-24 10:45:29','-11-25 23:03:54',0),(30,'userName19','123456','-11-24 10:45:29','-11-25 23:03:54',0),(31,'userName20','123456','-11-24 10:45:29','-11-25 23:03:54',0),(32,'userName21','123456','-11-24 10:45:29','-11-24 10:45:29',1),(33,'乔微尼','123456','-11-24 10:45:29','-11-25 23:05:48',1),(35,'userName24','123456','-11-24 10:45:30','-11-24 10:45:30',1),(36,'userName25','123456','-11-24 10:45:30','-11-24 10:45:30',1),(37,'userName26','123456','-11-24 10:45:30','-11-24 10:45:30',1),(38,'userName27','123456','-11-24 10:45:30','-11-24 10:45:30',1),(39,'userName28','123456','-11-24 10:45:30','-11-24 10:45:30',1),(40,'userName29','123456','-11-24 10:45:30','-11-24 10:45:30',1),(41,'userName30','123456','-11-24 10:45:30','-11-24 10:45:30',1),(42,'userName31','123456','-11-24 10:45:30','-11-24 10:45:30',1),(43,'userName32','123456','-11-24 10:45:30','-11-24 10:45:30',1),(44,'userName33','123456','-11-24 10:45:30','-11-24 10:45:30',1),(45,'userName34','123456','-11-24 10:45:30','-11-24 10:45:30',1),(46,'userName35','123456','-11-24 10:45:30','-11-24 10:45:30',1),(47,'userName36','123456','-11-24 10:45:30','-11-24 10:45:30',1),(48,'userName37','123456','-11-24 10:45:30','-11-24 10:45:30',1),(49,'userName38','123456','-11-24 10:45:30','-11-24 10:45:30',1),(50,'userName39','123456','-11-24 10:45:30','-11-24 10:45:30',1),(51,'userName40','123456','-11-24 10:45:30','-11-24 10:45:30',1),(52,'userName41','123456','-11-24 10:45:30','-11-24 10:45:30',1),(53,'userName42','123456','-11-24 10:45:30','-11-24 10:45:30',1),(54,'userName43','123456','-11-24 10:45:30','-11-24 10:45:30',1),(55,'userName44','123456','-11-24 10:45:30','-11-24 10:45:30',1),(56,'userName45','123456','-11-24 10:45:30','-11-24 10:45:30',1),(57,'userName46','123456','-11-24 10:45:30','-11-24 10:45:30',1),(58,'userName47','123456','-11-24 10:45:31','-11-24 10:45:31',1),(59,'userName48','123456','-11-24 10:45:31','-11-24 10:45:31',1),(60,'userName49','123456','-11-24 10:45:31','-11-24 10:45:31',1),(61,'userName50','123456','-11-24 10:45:31','-11-24 10:45:31',1),(62,'userName51','123456','-11-24 10:45:31','-11-24 10:45:31',1),(63,'userName52','123456','-11-24 10:45:31','-11-24 10:45:31',1),(64,'userName53','123456','-11-24 10:45:31','-11-24 10:45:31',1),(65,'userName54','123456','-11-24 10:45:31','-11-24 10:45:31',1),(66,'userName55','123456','-11-24 10:45:31','-11-24 10:45:31',1),(67,'userName56','123456','-11-24 10:45:31','-11-24 10:45:31',1),(68,'userName57','123456','-11-24 10:45:31','-11-24 10:45:31',1),(69,'userName58','123456','-11-24 10:45:31','-11-24 10:45:31',1),(70,'userName59','123456','-11-24 10:45:31','-11-24 10:45:31',1),(71,'userName60','123456','-11-24 10:45:31','-11-24 10:45:31',1),(72,'userName61','123456','-11-24 10:45:31','-11-24 10:45:31',1),(73,'userName62','123456','-11-24 10:45:31','-11-24 10:45:31',1),(74,'userName63','123456','-11-24 10:45:31','-11-24 10:45:31',1),(75,'userName64','123456','-11-24 10:45:31','-11-24 10:45:31',1),(76,'userName65','123456','-11-24 10:45:31','-11-24 10:45:31',1),(77,'userName66','123456','-11-24 10:45:31','-11-24 10:45:31',1),(78,'userName67','123456','-11-24 10:45:31','-11-24 10:45:31',1),(79,'userName68','123456','-11-24 10:45:31','-11-24 10:45:31',1),(80,'userName69','123456','-11-24 10:45:31','-11-24 10:45:31',1),(81,'userName70','123456','-11-24 10:45:31','-11-24 10:45:31',1),(82,'userName71','123456','-11-24 10:45:31','-11-24 10:45:31',1),(83,'userName72','123456','-11-24 10:45:31','-11-24 10:45:31',1),(84,'userName73','123456','-11-24 10:45:32','-11-24 10:45:32',1),(85,'userName74','123456','-11-24 10:45:32','-11-24 10:45:32',1),(86,'userName75','123456','-11-24 10:45:32','-11-24 10:45:32',1),(87,'userName76','123456','-11-24 10:45:32','-11-24 10:45:32',1),(88,'userName77','123456','-11-24 10:45:32','-11-24 10:45:32',1),(89,'userName78','123456','-11-24 10:45:32','-11-24 10:45:32',1),(90,'userName79','123456','-11-24 10:45:32','-11-24 10:45:32',1),(91,'userName80','123456','-11-24 10:45:32','-11-24 10:45:32',1),(92,'userName81','123456','-11-24 10:45:32','-11-24 10:45:32',1),(93,'userName82','123456','-11-24 10:45:32','-11-24 10:45:32',1),(94,'userName83','123456','-11-24 10:45:32','-11-24 10:45:32',1),(95,'userName84','123456','-11-24 10:45:32','-11-24 10:45:32',1),(96,'userName85','123456','-11-24 10:45:32','-11-24 10:45:32',1),(97,'userName86','123456','-11-24 10:45:32','-11-24 10:45:32',1),(98,'userName87','123456','-11-24 10:45:32','-11-24 10:45:32',1),(99,'userName88','123456','-11-24 10:45:32','-11-24 10:45:32',1),(100,'userName89','123456','-11-24 10:45:32','-11-24 10:45:32',1),(101,'userName90','123456','-11-24 10:45:32','-11-24 10:45:32',1),(102,'userName91','123456','-11-24 10:45:32','-11-24 10:45:32',1),(103,'userName92','123456','-11-24 10:45:32','-11-24 10:45:32',1),(104,'userName93','123456','-11-24 10:45:32','-11-24 10:45:32',1),(105,'userName94','123456','-11-24 10:45:32','-11-24 10:45:32',1),(106,'userName95','123456','-11-24 10:45:32','-11-24 10:45:32',1),(107,'userName96','123456','-11-24 10:45:32','-11-24 10:45:32',1),(108,'userName97','123456','-11-24 10:45:32','-11-24 10:45:32',1),(109,'userName98','123456','-11-24 10:45:32','-11-25 10:12:58',0),(110,'userName99','123456','-11-24 10:45:32','-11-25 10:12:58',0),(111,'userName100','123456','-11-24 10:45:33','-11-25 10:12:58',0),(115,'萧潜','1','-11-25 23:00:16','-11-25 23:00:16',1);/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

eclipse导入Web项目代码报错解决方案

原文链接

新闻管理系统——项目展示

“新闻管理”栏目

在周老师的指导、zyk同学的帮助下,完成的。啊哈哈、

Bootstrap4+MySQL前后端综合实训-Day08-PM【ajax获取表单标签内容 根据“栏目信息”添加“新闻信息” 新闻管理系统-项目展示】

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。