项目类型:JAVA WEB项目
用户类型:管理员+普通用户
主要技术:Jsp+Servlet+MySQL+Tomcat
前端html+css样式:使用了LayUI
开发工具:Eclipse (Idea导入需要配置信息)
对应环境介绍:JDK1.8+MySQL 5.7+Tomcat(MySQL8.0需要更换mysql-connector8.0.jar)
数据库表:3张
功能介绍:管理员通过发布新闻,用户注册 登录以后,可以在线查看新闻,并进行在线评价。总的来说,界面比较美观,且实现了应有功能的增删改查以及注册登录功能。
项目非开源(原创开发项目)
项目来源:项目获取方式
点击顶部
查看分类专栏了解获取
其他分类专栏也有不同类型的JavaWeb项目
图书管理系统(适用于课程实验)
视频演示如下:
【原创Java Web项目】基于Jsp+Servlet的新闻管理系统
1.dao:对数据库的访问,实现了增删改查
2.entity:定义了新闻、评论、用户三个实体,并设置对应实体的属性
3.filter:过滤器,设置字符编码都为utf8,防止乱码出现
4.service:业务逻辑处理
5.servlet:处理页面请求
6.utils:工具类
7.c3p0-config.xml:JDBC配置
以新闻增删改查为例
package com.news.entity;
public class News {//新闻表
private Integer id;
private String title;
private String content;
private String fbr;
private String fbsj;
private String imgUrl;
private String temp;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getFbr() {
return fbr;
}
public void setFbr(String fbr) {
this.fbr = fbr;
}
public String getFbsj() {
return fbsj;
}
public void setFbsj(String fbsj) {
this.fbsj = fbsj;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
}
获取新闻的信息
private NewsService service = new NewsService();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action=request.getParameter("action");//接受请求的参数
if(action != null && action.equals("newsList")) {
newsList(request, response);
}else if(action != null && action.equals("toAddNews")) {
toAddNews(request, response);
}else if(action != null && action.equals("deleteNews")) {
deleteNews(request, response);
}else if(action != null && action.equals("addNews")) {
addNews(request, response);
}else if(action != null && action.equals("toUpdateNews")) {
toUpdateNews(request, response);
}else if(action != null && action.equals("updateNews")) {
updateNews(request, response);
}else if(action != null && action.equals("recordList")) {
recordList(request, response);
}else if(action != null && action.equals("deleteNewsRecord")) {
deleteNewsRecord(request, response);
}else if(action != null && action.equals("newsListPer")) {
newsListPer(request, response);
}else if(action != null && action.equals("toRecord")) {
toRecord(request, response);
}else if(action != null && action.equals("addRecord")) {
addRecord(request, response);
}else if(action != null && action.equals("deleteRecords")) {
deleteRecords(request, response);
}
}
public void addNews(News news) {
dao.addNews(news);
}
通过insert into news (title,content,fbr,fbsj,imgUrl) values (?,?,?,?,?)SQL语句,往数据库的新闻表内添加数据。
public void addNews(News news) {
try {
runner.update("insert into news (title,content,fbr,fbsj,imgUrl) values (?,?,?,?,?)",
news.getTitle(),news.getContent(),news.getFbr(),news.getFbsj(),news.getImgUrl());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
-- ----------------------------
-- Table structure for news
-- ----------------------------
DROP TABLE IF EXISTS `news`;
CREATE TABLE `news` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`fbr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`fbsj` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`imgUrl` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for record
-- ----------------------------
DROP TABLE IF EXISTS `record`;
CREATE TABLE `record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nid` int(11) NULL DEFAULT NULL,
`plr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`plrid` int(11) NULL DEFAULT NULL,
`plsj` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`plnr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '1管理员 2普通用户',
`realName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;