目录
1 概述
本文主要阐述如何构建一个基于JSP等Web技术优化的B/S架构下的投稿,审稿,查询网站。从它的需求方面、系统的结构和原理、及基本设计思想、主要功能、具体实现的技术、具体的实现方法、存在的问题及其解决的方案等几个方面进行了讨论。分析了在线投稿审稿系统的发展意义, 并结合实际投稿审稿流程,详细分析了在稿件投稿审稿过程中作者、管理员等对系统的不同要求和系统必须实现的功能,包括作者的在线投稿与查稿,管理员在线管理审核等。
用户注册登陆管理
该模块实现新用户的注册及登陆验证功能。其中,注册用户会对用户输入的注册信息进行有效性验证,包括数据格式的有效性及逻辑有效性,例如检测用户名是否被占用等。
在线投稿:作者可以直接在线投稿
个人管理:用户可以修改自己的密码
在线投稿:作者可以直接在线投稿
个人管理:管理员可以修改自己的密码。
审核文章:对于分配给其的稿件进行审批,给出意见。不合格的作品可以直接删除。
人员管理:对已注册的用户进行权限分配,分配用户为专家权限或是屏蔽该用户。
文章管理:对所有文章进行查看,并具备删除功能。
2 数据库表
/*
Navicat MySQL Data Transfer
Source Server : localhost_3306
Source Server Version : 50540
Source Host : localhost:3306
Source Database : db_tougao
Target Server Type : MYSQL
Target Server Version : 50540
File Encoding : 65001
Date: 2019-05-06 16:26:53
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for t_admin
-- ----------------------------
DROP TABLE IF EXISTS `t_admin`;
CREATE TABLE `t_admin` (
`userId` int(11) NOT NULL AUTO_INCREMENT,
`userName` longtext,
`userPw` longtext,
PRIMARY KEY (`userId`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_admin
-- ----------------------------
INSERT INTO `t_admin` VALUES ('1', 'admin', '111111');
INSERT INTO `t_admin` VALUES ('2', 'dddd', 'dddd');
-- ----------------------------
-- Table structure for t_gaojian
-- ----------------------------
DROP TABLE IF EXISTS `t_gaojian`;
CREATE TABLE `t_gaojian` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` longtext,
`content` longtext,
`fujian` longtext,
`fujianYuanshiming` longtext,
`shijian` datetime DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`del` longtext,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_gaojian
-- ----------------------------
INSERT INTO `t_gaojian` VALUES ('9', '稿件1', '稿件已经发送请审核1', '/upload/1390305425978.jpg', '稿件1.doc', '2019-05-05 00:00:00', '8', 'pass');
INSERT INTO `t_gaojian` VALUES ('10', '稿件2', '稿件已经发送请审核2', '/upload/1390305442211.jpg', '稿件2.doc', '2019-05-05 00:00:00', '8', 'pass');
INSERT INTO `t_gaojian` VALUES ('11', '稿件3', '稿件已经发送请审核3', '/upload/1390290925586.jpg', '稿件3.doc', '2019-05-05 00:00:00', '6', 'pass');
INSERT INTO `t_gaojian` VALUES ('12', '稿件4', '稿件已经发送请审核4', '/upload/1390305633003.jpg', '稿件4.doc', '2019-05-05 00:00:00', '6', 'pass');
INSERT INTO `t_gaojian` VALUES ('13', '稿件5', '稿件已经发送请审核5', '/upload/1390351813602.jpg', '稿件5.doc', '2019-05-05 00:00:00', '9', 'pass');
INSERT INTO `t_gaojian` VALUES ('14', '我要上传一个稿件', '<p>管理员审核一下</p>', '/upload/1390718285131.doc', '稿件.doc', '2019-05-05 00:00:00', '10', 'pass');
INSERT INTO `t_gaojian` VALUES ('15', '111', '111请输入内容', '', '', '2019-05-05 00:00:00', '6', 'pass');
INSERT INTO `t_gaojian` VALUES ('16', 'kkkkk', '请输入内kkkkk容', '/upload/1396273062917.jpg', 'aa.jpg', '2019-05-06 16:24:36', '6', 'pass');
-- ----------------------------
-- Table structure for t_gonggao
-- ----------------------------
DROP TABLE IF EXISTS `t_gonggao`;
CREATE TABLE `t_gonggao` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` longtext,
`content` longtext,
`shijian` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_gonggao
-- ----------------------------
INSERT INTO `t_gonggao` VALUES ('4', '公告1', '新的系统上线欢迎意见', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('5', '公告2', '这里是公告内容', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('6', '公告3', '这里是公告内容4', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('7', '公告4', '这里是公告内容666', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('8', '公告5', '这里是公告内容344', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('9', '公告6', '这里是公告内容34', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('10', '公告7', '这里是公告内容ggg', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('11', '公告8', '这里是公告内容111', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('12', '公告9', '这里是公告内容999', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('13', '公告10', '这里是公告内容111', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('14', '公告11', '这里是公告内容55', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('17', '公告12', '这里是公告内容99', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('18', '公告11111', '这里是公告内容10', '2019-05-05 00:00:00');
INSERT INTO `t_gonggao` VALUES ('45', '最新的公告测试1440', ' 测试公告土土土土土土土土土ff', '2019-05-05 14:40:18');
-- ----------------------------
-- Table structure for t_pinglun
-- ----------------------------
DROP TABLE IF EXISTS `t_pinglun`;
CREATE TABLE `t_pinglun` (
`pinglunid` int(11) NOT NULL AUTO_INCREMENT,
`gaojianid` int(11) DEFAULT NULL,
`content` longtext,
`username` longtext,
`shijian` datetime DEFAULT NULL,
PRIMARY KEY (`pinglunid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_pinglun
-- ----------------------------
INSERT INTO `t_pinglun` VALUES ('3', '14', 'iiii', 'test', '2019-05-05 21:47:09');
-- ----------------------------
-- Table structure for t_user
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` longtext,
`sex` longtext,
`age` longtext,
`tel` longtext,
`address` longtext,
`loginName` longtext,
`loginPw` longtext,
`del` longtext,
`shijian` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_user
-- ----------------------------
INSERT INTO `t_user` VALUES ('1', '5', '5', '5', '5', '5', '5', '5', 'yes', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('2', '张三', '男', '22', '13455927413', '青岛', 'zhang', '00', 'yes', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('3', '1', '1', '1', '1', '1', '1', '11', 'yes', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('4', '4', '4', '4', '4', '4', '4', '4', 'yes', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('5', 'qwe', 'qwe', '22', '13244444', '北京', 'qwe', 'qwe', 'no', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('6', 'test', '男', '13', '2134321', '桂林', 'test', '111111', 'no', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('7', 'test12', '男', '23', '12312', '顺风使舵', 'test12', '123456', 'no', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('8', 'sssssssss', '男', '23', '6545665', 'sdfssdfsdf', 'aaaaaa', 'aaaaaa', 'no', '2019-05-05 00:00:00');
INSERT INTO `t_user` VALUES ('9', '李小小', '男', '45', '555555', '5555', 'rrrr', 'rrrr', 'no', '2019-05-05 14:36:35');
INSERT INTO `t_user` VALUES ('10', '李菠', '男', '26', '13112345678', '北京', 'asdfgh', '888888', 'no', '2019-05-05 14:36:35');
-- ----------------------------
-- Table structure for t_zhuanjia
-- ----------------------------
DROP TABLE IF EXISTS `t_zhuanjia`;
CREATE TABLE `t_zhuanjia` (
`userId` int(11) NOT NULL AUTO_INCREMENT,
`userName` longtext,
`userPw` longtext,
`name` longtext,
`sex` longtext,
`age` longtext,
`tel` longtext,
`address` longtext,
`shijian` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of t_zhuanjia
-- ----------------------------
INSERT INTO `t_zhuanjia` VALUES ('1', 'zj', '111111', '李专家', '男', '32', '13111113333', '北京', '2019-05-05 00:00:00');
3 关键代码
package com.action;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.DB;
import com.orm.TAdmin;
public class gonggao_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("gonggaoMana"))
{
gonggaoMana(req, res);
}
if(type.endsWith("gonggaoAdd"))
{
gonggaoAdd(req, res);
}
if(type.endsWith("gonggaoDel"))
{
gonggaoDel(req, res);
}
if(type.endsWith("gonggaoEdit"))
{
gonggaoEdit(req, res);
}
if(type.endsWith("gonggaoSaveEdit"))
{
gonggaoSaveEdit(req, res);
}
if(type.endsWith("gonggaoAll"))
{
gonggaoAll(req, res);
}
}
//显示公告编辑页面
public void gonggaoEdit(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
List gonggaoList=new ArrayList();
String sql="select * from t_gonggao where id="+Integer.parseInt(req.getParameter("id"));
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
List gonggao=new ArrayList();
gonggao.add(rs.getInt("id"));
gonggao.add(rs.getString("title"));
gonggao.add(rs.getString("content"));
gonggaoList.add(gonggao);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggaoList", gonggaoList);
req.getRequestDispatcher("admin/gonggao/gonggaoEdit.jsp").forward(req, res);
}
//保存编辑后的公告
public void gonggaoSaveEdit(HttpServletRequest req,HttpServletResponse res)
{
String title=req.getParameter("title");
String content=req.getParameter("content");
String shijian=new Date().toLocaleString();
System.out.println(req.getParameter("id")+"**gonggaoeditsave");
String sql="update t_gonggao set title=?,content=?,shijian=? where id="+Integer.parseInt(req.getParameter("id"));
Object[] params={title,content,shijian};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "gonggao?type=gonggaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
//管理员查看公告管理
public void gonggaoMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String page1=req.getParameter("page");
if(page1==null){
page1="1";
}
//分页设置
int EVERYPAGENUM=10;//每页条数
int page=Integer.parseInt(page1); //传递过来的当前页
int cou = 1;//得到信息总数
int pagecount=1; //总页数
String sql1="select count(*) as cou from t_gonggao";
Object[] params1={};
DB mydb1=new DB();
try
{
mydb1.doPstm(sql1, params1);
ResultSet rs=mydb1.getRs();
while(rs.next())
{
cou= rs.getInt("cou");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb1.closed();
if (cou % EVERYPAGENUM == 0) {
pagecount= cou / EVERYPAGENUM;
} else {
pagecount=cou / EVERYPAGENUM + 1;
}
req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);
req.setAttribute("page", page);
req.setAttribute("cou", cou);
req.setAttribute("pagecount", pagecount);
List gonggaoList=new ArrayList();
String sql="select * from t_gonggao order by id desc";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
List gonggao=new ArrayList();
gonggao.add(rs.getInt("id"));
gonggao.add(rs.getString("title"));
gonggao.add(rs.getString("content"));
gonggao.add(rs.getDate("shijian"));
gonggaoList.add(gonggao);
} else {
break; //减少空循环的时间
}
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggaoList", gonggaoList);
req.getRequestDispatcher("admin/gonggao/gonggaoMana.jsp").forward(req, res);
}
//添加公告保存
public void gonggaoAdd(HttpServletRequest req,HttpServletResponse res)
{
String title=req.getParameter("title");
String content=req.getParameter("content");
String shijian=new Date().toLocaleString();
String sql="insert into t_gonggao values(?,?,?)";
Object[] params={title,content,shijian};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "gonggao?type=gonggaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
//公告删除
public void gonggaoDel(HttpServletRequest req,HttpServletResponse res)
{
System.out.println(req.getParameter("id")+"**");
String sql="delete from t_gonggao where id="+Integer.parseInt(req.getParameter("id"));
Object[] params={};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "gonggao?type=gonggaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
//普通用户查看公告
public void gonggaoAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String page1=req.getParameter("page");
if(page1==null){
page1="1";
}
//分页设置
int EVERYPAGENUM=10;//每页条数
int page=Integer.parseInt(page1); //传递过来的当前页
int cou = 1;//得到信息总数
int pagecount=1; //总页数
String sql1="select count(*) as cou from t_gonggao";
Object[] params1={};
DB mydb1=new DB();
try
{
mydb1.doPstm(sql1, params1);
ResultSet rs=mydb1.getRs();
while(rs.next())
{
cou= rs.getInt("cou");
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb1.closed();
if (cou % EVERYPAGENUM == 0) {
pagecount= cou / EVERYPAGENUM;
} else {
pagecount=cou / EVERYPAGENUM + 1;
}
req.setAttribute("EVERYPAGENUM", EVERYPAGENUM);
req.setAttribute("page", page);
req.setAttribute("cou", cou);
req.setAttribute("pagecount", pagecount);
List gonggaoList=new ArrayList();
String sql="select * from t_gonggao order by id desc";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
List gonggao=new ArrayList();
gonggao.add(rs.getString("id"));
gonggao.add(rs.getString("title"));
gonggao.add(rs.getString("content"));
gonggao.add(rs.getDate("shijian"));
gonggaoList.add(gonggao);
} else {
break; //减少空循环的时间
}
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggaoList", gonggaoList);
req.getRequestDispatcher("auser/gonggao/gonggaoAll.jsp").forward(req, res);
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}