News management system of Jsp+Servlet+Filter (original Java homework project)

Project type: JAVA WEB project
User type: administrator + ordinary user
Main technology: Jsp+Servlet+MySQL+Tomcat
Front end html+css Style: LayUI is used
Development tool: Eclipse (configuration information is required for Idea import)
Corresponding environment introduction: jdk1 8 + MySQL 5.7 + Tomcat (MySQL connector 8.0.jar needs to be replaced for MySQL 8.0)
Database table: 3 sheets
Function introduction: after the administrator publishes the news and the user registers and logs in, he can view the news online and make online evaluation. In general, the interface is relatively beautiful, and the functions of addition, deletion, modification, query and registration are realized.

The project is not open source
Project source: "that senior" (V) (public)
Click on the top
See column introduction for

0 project structure design

1.dao: the access to the database realizes the addition, deletion, modification and query
2.entity: defines three entities: news, comment and user, and sets the attributes of the corresponding entities
3.filter: filter. Set the character codes to utf8 to prevent random codes
4.service: business logic processing
5.servlet: processing page requests
6.utils: tool class
7.c3p0-config.xml: JDBC configuration

1. Introduction to administrator functions

1.1 login

1.2 user registration

1.3 published news

1.4 press release

You can upload the corresponding news cover and enter the specific information of the news.

1.5 viewing user comments

After the news release, the user will evaluate, and the administrator can see the user's evaluation content

2 user function introduction

2.1 registration

After registration, go to login

2.2 viewing news and comments


After commenting, you can delete the comment content

2.3 online comments

3 code introduction of function implementation

Take the addition, deletion, modification and investigation of news as an example

3.1 define entity class news java

package com.news.entity;

public class News {//News table
	
	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;
	}

}

3.2NewsServlet.java class

Get news information

	private NewsService service = new NewsService();
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
		    String action=request.getParameter("action");//Accept requested parameters
		    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);
			}
		    
		}
	

3.3NewsService.java class

	public void addNews(News news) {
		dao.addNews(news);	
	}

3.4NewsDao.java class

insert into news (title,content,fbr,fbsj,imgUrl) values (?,?,?,?,?)SQL statement to add data to the news table of the database.

	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);
        }

	}

4 establishment of database table

4.1 news sheet

-- ----------------------------
-- 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;

4.2 comment form

-- ----------------------------
-- 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;

4.3 user table

-- ----------------------------
-- 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 Administrator 2 ordinary user',
  `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;

Keywords: Java MySQL JSP servlet filter

Added by lobski on Sat, 22 Jan 2022 21:38:54 +0200