Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

一、功能简介

首页【index.jsp】:

    1、显示最新消息,单击消息的链接,可以查看具体的消息内容及其回复和批复

    2、如果员工已登陆,则显示其信息

消息列表【messageList.jsp】:

    1、以分页的形式,显示消息列表,单击消息的链接,可以查看具体的消息内容和批复

发布新消息【publishNewMessage.jsp】:

    1、发布新的消息

身份识别【login.jsp】:

    1、登陆

二、使用到的javaweb知识及其它:

1、jsp

2、servlet

3、filter

4、jdbc

5、db-utils

6、ckeditor

三、运行环境

OS:win7 64位

IDE:Eclipse EE 4.4.1

MySql:5.5.40

JDK:1.7

Tomcat:7

四、项目源代码

可在如下网盘链接中下载源码和mysql数据库备份文件位置见下图

http://yunpan.cn/ccT4xugIKDeps  访问密码 7b0c

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第1张图片


mysql:


-- MySQL dump 10.13  Distrib 5.5.40, for Win32 (x86)
--
-- Host: localhost    Database: jc_1
-- ------------------------------------------------------
-- Server version	5.5.40

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!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 */;

--
-- Table structure for table `tb_criticism`
--

DROP TABLE IF EXISTS `tb_criticism`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tb_criticism` (
  `criticismID` int(11) NOT NULL AUTO_INCREMENT,
  `criticismContent` text,
  `employeeID` int(11) DEFAULT NULL,
  `criticismTime` datetime DEFAULT NULL,
  `messageID` int(11) DEFAULT NULL,
  PRIMARY KEY (`criticismID`),
  KEY `employeeID` (`employeeID`),
  KEY `messageID` (`messageID`)
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tb_criticism`
--

LOCK TABLES `tb_criticism` WRITE;
/*!40000 ALTER TABLE `tb_criticism` DISABLE KEYS */;
INSERT INTO `tb_criticism` VALUES (5,'

测试批复

',3052,'2010-01-26 20:53:06',16),(19,'测试',1002,'2015-08-10 22:23:16',21),(20,'批复测试0001',1002,'2015-08-10 22:23:37',24),(21,'发布批复001',1002,'2015-08-10 22:24:35',23),(22,'ckeditor批复测试',1002,'2015-08-10 22:25:50',22); /*!40000 ALTER TABLE `tb_criticism` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tb_employee` -- DROP TABLE IF EXISTS `tb_employee`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tb_employee` ( `employeeID` int(11) NOT NULL AUTO_INCREMENT, `employeeName` varchar(20) DEFAULT NULL, `employeeSex` varchar(5) DEFAULT NULL, `employeeBirth` date DEFAULT NULL, `employeePhone` varchar(20) DEFAULT NULL, `employeePlace` varchar(50) DEFAULT NULL, `joinTime` date DEFAULT NULL, `password` varchar(20) DEFAULT NULL, `isLead` int(1) DEFAULT NULL, PRIMARY KEY (`employeeID`) ) ENGINE=InnoDB AUTO_INCREMENT=1006 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tb_employee` -- LOCK TABLES `tb_employee` WRITE; /*!40000 ALTER TABLE `tb_employee` DISABLE KEYS */; INSERT INTO `tb_employee` VALUES (1001,'老狼','男','1991-12-06','15382009723','中国','2005-05-18','fcl1164891',0),(1002,'小代码','男','1991-12-06','15382009723','中国','2005-05-18','fcl1164891',1),(1003,'散人','男','1991-12-06','15382009723','中国','2005-05-18','fcl1164891',0),(1004,'行者','男','1991-12-06','15382009723','中国','2005-05-18','fcl1164891',1),(1005,'小龙女','女','1991-12-06','15382009723','中国','2005-05-18','fcl1164891',1); /*!40000 ALTER TABLE `tb_employee` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tb_message` -- DROP TABLE IF EXISTS `tb_message`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tb_message` ( `messageID` int(11) NOT NULL AUTO_INCREMENT, `messageTitle` varchar(50) DEFAULT NULL, `messageContent` text, `employeeID` int(11) DEFAULT NULL, `publishTime` datetime DEFAULT NULL, PRIMARY KEY (`messageID`), KEY `employeeID` (`employeeID`) ) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tb_message` -- LOCK TABLES `tb_message` WRITE; /*!40000 ALTER TABLE `tb_message` DISABLE KEYS */; INSERT INTO `tb_message` VALUES (14,'网络维护公告','

为保证网络上网,网络信息中心特安排了网络维护人员值班。各用户如有网络故障,请按以下方式联系。

\r\n

 值班电话:XXXXXX

\r\n

 值班人:周先生

',3052,'2009-08-25 14:18:59'),(16,'开会通知','

请开发部的所有人员于8月30日的下午2点到三楼会议室,会议重要,请勿缺席。

',3052,'2009-08-25 14:27:54'),(17,'研发部会议通知','

请研发部的所有人员于8月30日的下午2点到三楼会议室,会议重要,请勿缺席!!

',3052,'2009-08-25 14:33:51'),(18,'关于国庆放假的通知','

按国家规定国庆放假七天,8月8日正常上班。

',3052,'2009-08-25 14:35:35'),(19,'请假一天,望领导能批准','

由于家里有事情,急需处理,现请假一天,忘领导能批准。

',3052,'2009-08-25 14:37:02'),(20,'测试','HelloWorld',1001,'2015-07-28 17:44:38'),(21,'测试一','测试一',1001,'2015-07-28 21:26:47'),(22,'ckeditor测试','

\r\n ckeditor测试

\r\n',1001,'2015-07-30 00:20:34'),(23,'发布测试001','

\r\n 发布测试

\r\n',1001,'2015-08-10 05:09:19'),(24,'发布测试003','

\r\n 发布测试

\r\n',1002,'2015-08-10 05:12:52'); /*!40000 ALTER TABLE `tb_message` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tb_reply` -- DROP TABLE IF EXISTS `tb_reply`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tb_reply` ( `replyID` int(11) NOT NULL AUTO_INCREMENT, `replyContent` text, `employeeID` int(11) DEFAULT NULL, `replyTime` datetime DEFAULT NULL, `messageID` int(11) DEFAULT NULL, PRIMARY KEY (`replyID`), KEY `employeeID` (`employeeID`), KEY `messageID` (`messageID`) ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tb_reply` -- LOCK TABLES `tb_reply` WRITE; /*!40000 ALTER TABLE `tb_reply` DISABLE KEYS */; INSERT INTO `tb_reply` VALUES (9,'

太好了,希望以后不要再无故掉线了!!!

',3052,'2009-08-25 15:03:23',14),(10,'

是哦,总算是能够安心上网了。

',3052,'2009-08-25 15:03:49',14),(11,'

测试回复

',3052,'2010-01-26 20:52:26',14),(12,'回复一',1001,'2015-07-28 21:38:35',21),(13,'回复一',1001,'2015-07-28 21:38:58',21),(17,'回复测试,回复测试',1002,'2009-08-05 12:15:14',22),(18,'

\r\n 测试回复

\r\n',1002,'2015-08-10 04:14:49',22),(19,'

\r\n 第四次回复

\r\n',1002,'2015-08-10 04:17:03',22),(20,'

\r\n 第五次回复

\r\n',1002,'2015-08-10 04:27:00',22),(21,'

\r\n 回复测试

\r\n',1002,'2015-08-10 05:12:24',23); /*!40000 ALTER TABLE `tb_reply` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2015-08-15 15:14:15




java代码:

src目录结构:


D:\program\java\tomcat\tomcat7\webapps\jc\jc_my_1_1\src>tree /f
卷 软件 的文件夹 PATH 列表
卷序列号为 0006-17B7
D:.
└─com
    └─laolang
        ├─dao
        │      CriticismDao.java
        │      EmployeeDao.java
        │      MessageDao.java
        │      ReplyDao.java
        │
        ├─daoImpl
        │      CriticismDaoImpl.java
        │      EmployeeDaoImpl.java
        │      MessageDaoImpl.java
        │      ReplyDaoImpl.java
        │
        ├─db
        │      db-config.properties
        │      laolangDB.java
        │      Page.java
        │      PageUtil.java
        │
        ├─domain
        │      Criticism.java
        │      Employee.java
        │      Message.java
        │      Reply.java
        │
        ├─filter
        │      CharsetEncodingFilter.java
        │
        └─servlet
                CriticismServlet.java
                loginServlet.java
                MessageContentServlet.java
                MessageListServlet.java
                PublishNewMessageServlet.java
                ReplyServlet.java


D:\program\java\tomcat\tomcat7\webapps\jc\jc_my_1_1\src>
其中dao是数据库接口,daoImpl是其实现,db是工具类,包括数据库信息,数据库的打开关闭工具类,分页相关工具类,domain中的类对应数据库中的表,filter是过滤器,其功能为过滤整个网站的字符编码为UTF-8,servlet是处理各种请求的自定义servlet


com.laolang.dao.CriticismDao


package com.laolang.dao;

import java.sql.SQLException;

import com.laolang.domain.Criticism;

/**
 * 消息批复数据库操作接口
 * 
 * @author 小代码
 * @version 1.0
 * 
 */
public interface CriticismDao {

	/**
	 * 插入批复
	 *
	 * @param criticism
	 *            要插入的批复对象
	 * @throws SQLException
	 *             the SQL exception
	 */
	public void insertCriticism(Criticism criticism) throws SQLException;

	/**
	 * 根据已发布消息的ID查找批复
	 * @param criticism
	 *            已发布消息的ID
	 * @return 查找到的批复
	 * @throws SQLException
	 *             the SQL exception
	 */
	public Criticism selectCriticismByMessageId( int messageID ) throws SQLException;
}

com.laolang.dao.EmployeeDao



package com.laolang.dao;

import java.sql.SQLException;

import com.laolang.domain.Employee;



/**
 * Employee 数据库操作接口.
 * 
 * @author 小代码
 * @version 1.0
 */
public interface EmployeeDao {

	/**
	 * 通过员工ID查找员工.
	 * 
	 * @param id
	 *            员工ID
	 * @return 查找到的员工对象
	 * @throws SQLException
	 *             the SQL exception
	 */
	public Employee selectById(int id) throws SQLException;
}

com.laolang.dao.MessageDao



package com.laolang.dao;

import java.util.List;

import com.laolang.db.Page;
import com.laolang.domain.Message;

/**
 * 消息数据库操作接口
 * 
 * @author 小代码
 * @version 1.0
 */
public interface MessageDao {

	/**
	 * 添加消息的方法
	 *
	 * @param message
	 *            要添加的消息
	 */
	public void insertMessage(Message message);

	/**
	 * 修改消息的方法
	 *
	 * @param message
	 *            要修改的消息
	 */
	public void updateMessage(Message message);

	/**
	 * 删除消息的方法
	 *
	 * @param messageID
	 *            要删除的消息的ID
	 */
	public void deleteMessage(int messageID);

	/**
	 * 按分页信息查询所有消息的方法
	 *
	 * @param page
	 *            分页
	 * @return 查询到的消息列表
	 */
	public List selectMesssageAll(Page page);

	/**
	 * 按ID查询消息的方法
	 *
	 * @param messageID
	 *            要查询的消息的ID
	 * @return 查询到的消息ID
	 */
	public Message selectMessageById(int messageID);

	/**
	 * 查询消息记录数
	 *
	 * @return 消息总条数
	 */
	public int selectMessageCount();
}





com.laolang.dao.ReplyDao


package com.laolang.dao;

import java.sql.SQLException;
import java.util.List;

import com.laolang.db.Page;
import com.laolang.domain.Reply;

/**
 * 消息回复数据库操作接口
 * 
 * @author 小代码
 * @version 1.0
 */
public interface ReplyDao {

	/**
	 * 插入回复
	 *
	 * @param reply
	 *            消息回复对象
	 * @throws SQLException
	 *             the SQL exception
	 */
	public void insertReply(Reply reply) throws SQLException;

	/**
	 * 根据已发布消息的ID查找其所有回复
	 *
	 * @param messageID
	 *            已发布消息的ID
	 * @param page
	 *            分页类对象
	 * @return 查询到的回复消息
	 * @throws SQLException
	 *             the SQL exception
	 */
	public List selectReplyByMesageId(int messageID, Page page)
			throws SQLException;

	/**
	 * 根据已发布的消息的ID查询其回复数
	 *
	 * @param messageID
	 *            已发布消息的ID
	 * @return 回复数
	 * @throws SQLException
	 *             the SQL exception
	 */
	public int selectReplyCountByMessageId(int messageID) throws SQLException;
}

com.laolang.daoImpl.CriticismDaoImpl



package com.laolang.daoImpl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.laolang.dao.CriticismDao;
import com.laolang.db.laolangDB;
import com.laolang.domain.Criticism;

/**
 * 消息批复数据库操作实现
 * 
 * @author 小代码
 * @version 1.0
 */
public class CriticismDaoImpl implements CriticismDao {

	public CriticismDaoImpl() {
		runner = new QueryRunner();
	}

	/**
	 * 插入批复
	 *
	 * @param criticism
	 *            要插入的批复对象
	 * @throws SQLException
	 *             the SQL exception
	 * @see com.laolang.dao.CriticismDao#insertCriticism(com.laolang.domain.Criticism)
	 */
	@Override
	public void insertCriticism(Criticism criticism) throws SQLException {
		String sql = "insert into tb_criticism (criticismContent,employeeID,criticismTime,messageID) values(?,?,?,?)";
		runner.update(laolangDB.getConnection(), sql,
				criticism.getCriticismContent(), criticism.getEmployeeID(),
				criticism.getCriticismTime(), criticism.getMessageID());
	}

	/**
	 * 根据已发布消息的ID查找批复
	 * 
	 * @param criticism
	 *            已发布消息的ID
	 * @return 查找到的批复
	 * @throws SQLException
	 *             the SQL exception
	 * @see com.laolang.dao.CriticismDao#selectCriticismByMessageId()
	 */
	@Override
	public Criticism selectCriticismByMessageId(int messageID)
			throws SQLException {
		String sql = "select criticismContent,employeeID,criticismTime,messageID from tb_criticism where messageID=?";
		Criticism criticism = runner.query(laolangDB.getConnection(), sql,
				new BeanHandler(Criticism.class), messageID);

		return criticism;
	}

	private QueryRunner runner;

}

com.laolang.daoImpl.EmployeeDaoImpl



package com.laolang.daoImpl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.laolang.dao.EmployeeDao;
import com.laolang.db.laolangDB;
import com.laolang.domain.Employee;

/**
 * employee 数据库操作接口实现
 * 
 * @author 小代码
 * @version 1.0
 */
public class EmployeeDaoImpl implements EmployeeDao {
	
	

	/**
	 * Instantiates a new employee dao impl.
	 */
	public EmployeeDaoImpl() {
		super();
		runner = new QueryRunner();
	}

	/** 
	 * 根据id查询员工信息 
	 * 
	 * @param id
	 * 		员工ID
	 * @return
	 * 		查询到的员工对象
	 * 
	 * @see com.laolang.dao.EmployeeDao#selectById(int)
	 */
	@Override
	public Employee selectById(int id) throws SQLException {
		Employee emp = null;
		String selectById = "select employeeID,employeeName,employeeSex,"
				+ "employeeBirth,employeePhone,employeePlace,joinTime,password,isLead "
				+ "from tb_employee where employeeID=?";
		emp = runner.query(laolangDB.getConnection(), selectById, new BeanHandler(Employee.class), id);
		return emp;
	}

	/** The runner. */
	private QueryRunner runner;
}

com.laolang.daoImpl.MessageDaoImpl



package com.laolang.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.laolang.dao.MessageDao;
import com.laolang.db.Page;
import com.laolang.db.laolangDB;
import com.laolang.domain.Message;

/**
 * 消息数据库操作接口
 * 
 * @author 小代码
 * @version 1.0
 */
public class MessageDaoImpl implements MessageDao {

	/**
	 * Instantiates a new message dao impl.
	 */
	public MessageDaoImpl() {
		runner = new QueryRunner();
	}

	/** 
	 * 
	 * 添加消息的方法
	 *
	 * @param message
	 *            要添加的消息
	 * @see com.laolang.dao.MessageDao#insertMessage(com.laolang.domain.Message)
	 */
	@Override
	public void insertMessage(Message message) {
		String sqlInsert = "insert into tb_message values(?,?,?,?,?)";
		try {
			runner.update(laolangDB.getConnection(), sqlInsert,
					message.getMessageID(), message.getMessageTitle(),
					message.getMessageContent(), message.getEmployeeID(),
					message.getPublishTime());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * 修改消息的方法
	 *
	 * @param message
	 *            要修改的消息
	 * @see com.laolang.dao.MessageDao#updateMessage(com.laolang.domain.Message)
	 */
	@Override
	public void updateMessage(Message message) {

	}

	/**
	 * 
	 * 删除消息的方法
	 *
	 * @param messageID
	 *            要删除的消息的ID
	 * @see com.laolang.dao.MessageDao#deleteMessage(int)
	 */
	@Override
	public void deleteMessage(int messageID) {

	}

	/**
	 * 
	 * 按分页信息查询所有消息的方法
	 *
	 * @param page
	 *            分页
	 * @return 查询到的消息列表
	 * @see com.laolang.dao.MessageDao#selectMesssageAll(com.laolang.db.Page)
	 */
	@Override
	public List selectMesssageAll(Page page) {
		List messageList = null;
		String selectAll = "select messageID,messageTitle,messageContent,employeeID,publishTime from tb_message order by publishTime desc limit ?,?";
		try {
			messageList = runner.query(laolangDB.getConnection(), selectAll,
					new BeanListHandler(Message.class),page.getBeginIndex(),page.getEveryPage());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return messageList;
	}

	/**
	 * 
	 * 按ID查询消息的方法
	 *
	 * @param messageID
	 *            要查询的消息的ID
	 * @return 查询到的消息ID
	 * @see com.laolang.dao.MessageDao#selectMessageById(int)
	 */
	@Override
	public Message selectMessageById(int messageID) {
		Message message = null;
		
		String select = "select messageID,messageTitle,messageContent,employeeID,publishTime from tb_message where messageID = ?";
		try {
			message = runner.query(laolangDB.getConnection(), select, new BeanHandler(Message.class),messageID);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return message;
	}

	/**
	 * 查询消息记录数
	 *
	 * @return 消息总条数
	 * @see com.laolang.dao.MessageDao#selectMessageCount()
	 */
	@Override
	public int selectMessageCount() {
		Connection conn = laolangDB.getConnection();
		String sqlCount = "select count(messageID) from tb_message";
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count = 0;
		try{
			ps = conn.prepareStatement(sqlCount);
			rs = ps.executeQuery();
			if( rs.next() ){
				count = rs.getInt(1);
			}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			laolangDB.closeConnection(rs, ps, conn);
		}
		return count;
	}

	/** The runner. */
	private QueryRunner runner;

}

com.laolang.daoImpl.ReplyDaoImpl



package com.laolang.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.laolang.dao.ReplyDao;
import com.laolang.db.Page;
import com.laolang.db.laolangDB;
import com.laolang.domain.Reply;

/**
 * 消息回复数据库操作实现
 * 
 * @author 小代码
 * @version 1.0
 */
public class ReplyDaoImpl implements ReplyDao {

	public ReplyDaoImpl() {
		runner = new QueryRunner();
	}

	/**
	 * 插入回复
	 *
	 * @param reply
	 *            消息回复对象
	 * @throws SQLException
	 *             the SQL exception
	 * @see com.laolang.dao.ReplyDao#insertReply(com.laolang.domain.Reply)
	 */
	@Override
	public void insertReply(Reply reply) throws SQLException {
		String sqlInsert = "insert into tb_reply values(?,?,?,?,?)";
		runner.update(laolangDB.getConnection(), sqlInsert, reply.getReplyID(),
				reply.getReplyContent(), reply.getEmployeeID(),
				reply.getReplyTime(), reply.getMessageID());

	}

	/**
	 * 根据已发布消息的ID查找其所有回复
	 *
	 * @param messageID
	 *            已发布消息的ID
	 * @param page
	 *            分页类对象
	 * @return 查询到的回复消息
	 * @throws SQLException
	 *             the SQL exception
	 * @see com.laolang.dao.ReplyDao#selectReplyByMesageId(int,
	 *      com.laolang.db.Page)
	 */
	@Override
	public List selectReplyByMesageId(int messageID, Page page)
			throws SQLException {
		String sql = "select replyID,replyContent,employeeID,replyTime,messageID from tb_reply where messageID=? limit ?,?";
		List replyList = runner.query(laolangDB.getConnection(), sql,
				new BeanListHandler(Reply.class), messageID,
				page.getBeginIndex(), page.getEveryPage());
		return replyList;
	}

	/**
	 * 根据已发布的消息的ID查询其回复数
	 *
	 * @param messageID
	 *            已发布消息的ID
	 * @return 回复数
	 * @throws SQLException
	 *             the SQL exception
	 * @see com.laolang.dao.ReplyDao#selectReplyCountByMessageId(int)
	 */
	@Override
	public int selectReplyCountByMessageId(int messageID) throws SQLException {
		Connection conn = laolangDB.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		int count = 0;
		String sql = "select count(messageID) from tb_reply where messageID = ?";
		
		ps = conn.prepareStatement(sql);
		ps.setInt(1, messageID);
		rs = ps.executeQuery();
		if( rs.next() ){
			count = rs.getInt(1);
		}
		return count;
	}

	private QueryRunner runner;
}

com.laolang.db.db-config.properties



jdbc.url=jdbc:mysql://localhost:3306/jc_1
jdbc.username=root
jdbc.userpassword=123456
jdbc.driver=com.mysql.jdbc.Driver

com.laolang.db.laolangDB



package com.laolang.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

/**
 * 数据库连接和关闭工具类
 */
public class laolangDB {

	/** 数据库连接地址 */
	private static String URL;

	/** 数据库用户名 */
	private static String USERNAME;

	/** 数据库密码 */
	private static String USERPASSWORD;

	/** mysql 驱动 */
	private static String DRIVER;

	/** The rb. */
	private static ResourceBundle rb = ResourceBundle
			.getBundle("com.laolang.db.db-config");

	/**
	 * 使用静态代码块加载驱动
	 */
	static {
		URL = rb.getString("jdbc.url");
		USERNAME = rb.getString("jdbc.username");
		USERPASSWORD = rb.getString("jdbc.userpassword");
		DRIVER = rb.getString("jdbc.driver");

		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获得链接.
	 *
	 * @return the connection
	 */
	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(URL, USERNAME, USERPASSWORD);
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return conn;
	}

	/**
	 * 关闭链接.
	 *
	 * @param rs            the rs
	 * @param ps            the ps
	 * @param conn            the conn
	 */
	public static void closeConnection(ResultSet rs, Statement ps,
			Connection conn) {
		try {
			if (null != rs)
				rs.close();
			if (null != ps)
				ps.close();
			if (null != conn)
				conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

com.laolang.db.Page



package com.laolang.db;

/**
 * 分页信息类,用于封装分页的所有信息
 * 
 * @author 小代码
 * @version 1.0
 */
public class Page {

	/**
	 * 创建一个分页信息类
	 *
	 * @param everyPage
	 *            每页显示记录数
	 * @param totalCount
	 *            总记录数
	 * @param totalPage
	 *            总页数
	 * @param currentPage
	 *            当前页
	 * @param beginIndex
	 *            查询起始点
	 * @param hasPrePage
	 *            是否有上一页
	 * @param hasNextPage
	 *            是否有下一页
	 */
	public Page(int everyPage, int totalCount, int totalPage, int currentPage,
			int beginIndex, boolean hasPrePage, boolean hasNextPage) { // 自定义构造方法
		this.everyPage = everyPage;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
		this.currentPage = currentPage;
		this.beginIndex = beginIndex;
		this.hasPrePage = hasPrePage;
		this.hasNextPage = hasNextPage;
	}

	@Override
	public String toString() {
		return "Page [everyPage=" + everyPage + ", totalCount=" + totalCount
				+ ", totalPage=" + totalPage + ", currentPage=" + currentPage
				+ ", beginIndex=" + beginIndex + ", hasPrePage=" + hasPrePage
				+ ", hasNextPage=" + hasNextPage + "]";
	}

	/**
	 * Instantiates a new page.
	 */
	public Page() {
	} // 默认构造函数

	/**
	 * Gets the every page.
	 *
	 * @return the every page
	 */
	public int getEveryPage() { // 获得每页显示记录数
		return everyPage;
	}

	/**
	 * Sets the every page.
	 *
	 * @param everyPage
	 *            the new every page
	 */
	public void setEveryPage(int everyPage) {// 设置每页显示记录数
		this.everyPage = everyPage;
	}

	/**
	 * Gets the total count.
	 *
	 * @return the total count
	 */
	public int getTotalCount() {// 获得总记录数
		return totalCount;
	}

	/**
	 * Sets the total count.
	 *
	 * @param totalCount
	 *            the new total count
	 */
	public void setTotalCount(int totalCount) {// 设置总记录数
		this.totalCount = totalCount;
	}

	/**
	 * Gets the total page.
	 *
	 * @return the total page
	 */
	public int getTotalPage() {// 获得总页数
		return totalPage;
	}

	/**
	 * Sets the total page.
	 *
	 * @param totalPage
	 *            the new total page
	 */
	public void setTotalPage(int totalPage) {// 设置总页数
		this.totalPage = totalPage;
	}

	/**
	 * Gets the current page.
	 *
	 * @return the current page
	 */
	public int getCurrentPage() {// 获得当前页
		return currentPage;
	}

	/**
	 * Sets the current page.
	 *
	 * @param currentPage
	 *            the new current page
	 */
	public void setCurrentPage(int currentPage) {// 设置当前页
		this.currentPage = currentPage;
	}

	/**
	 * Gets the begin index.
	 *
	 * @return the begin index
	 */
	public int getBeginIndex() {// 获得查询起始点
		return beginIndex;
	}

	/**
	 * Sets the begin index.
	 *
	 * @param beginIndex
	 *            the new begin index
	 */
	public void setBeginIndex(int beginIndex) {// 设置查询起始点
		this.beginIndex = beginIndex;
	}

	/**
	 * Checks if is checks for pre page.
	 *
	 * @return true, if is checks for pre page
	 */
	public boolean isHasPrePage() {// 获得是否有上一页
		return hasPrePage;
	}

	/**
	 * Sets the checks for pre page.
	 *
	 * @param hasPrePage
	 *            the new checks for pre page
	 */
	public void setHasPrePage(boolean hasPrePage) {// 设置是否有上一页
		this.hasPrePage = hasPrePage;
	}

	/**
	 * Checks if is checks for next page.
	 *
	 * @return true, if is checks for next page
	 */
	public boolean isHasNextPage() {// 获得是否有下一页
		return hasNextPage;
	}

	/**
	 * Sets the checks for next page.
	 *
	 * @param hasNextPage
	 *            the new checks for next page
	 */
	public void setHasNextPage(boolean hasNextPage) {// 设置是否有下一页
		this.hasNextPage = hasNextPage;
	}

	/** 每页显示记录数 */
	private int everyPage;

	/** 总记录数 */
	private int totalCount;

	/** 总页数 */
	private int totalPage;

	/** 当前页 */
	private int currentPage;

	/** 查询起始点 */
	private int beginIndex;

	/** 是否有上一页 */
	private boolean hasPrePage;

	/** 是否有下一页 */
	private boolean hasNextPage;
}

com.laolang.db.PageUtil



package com.laolang.db;

/**
* 分页信息辅助类
* 
* @author 小代码
* @version 1.0
*/
public class PageUtil {

	/**
	 * 创建分页信息对象
	 *
	 * @param everyPage
	 *            每页显示消息数
	 * @param totalCount
	 *            总页数
	 * @param currentPage
	 *            当前页
	 * @return the page
	 */
	public static Page createPage(int everyPage, int totalCount, int currentPage) {
		everyPage = getEveryPage(everyPage);
		currentPage = getCurrentPage(currentPage);
		int totalPage = getTotalPage(everyPage, totalCount);
		int beginIndex = getBeginIndex(everyPage, currentPage);
		boolean hasPrePage = getHasPrePage(currentPage);
		boolean hasNextPage = getHasNextPage(totalPage, currentPage);
		return new Page(everyPage, totalCount, totalPage, currentPage,
				beginIndex, hasPrePage, hasNextPage);
	}

	/**
	 * 获得每页显示记录数
	 *
	 * @param everyPage
	 *            the every page
	 * @return the every page
	 */
	public static int getEveryPage(int everyPage) {
		return everyPage == 0 ? 10 : everyPage;
	}

	/**
	 * 获得当前页
	 *
	 * @param currentPage
	 *            the current page
	 * @return the current page
	 */
	public static int getCurrentPage(int currentPage) {
		return currentPage == 0 ? 1 : currentPage;
	}

	/**
	 * 获得总页数
	 *
	 * @param everyPage
	 *            the every page
	 * @param totalCount
	 *            the total count
	 * @return the total page
	 */
	public static int getTotalPage(int everyPage, int totalCount) {
		int totalPage = 0;
		if (totalCount != 0 && totalCount % everyPage == 0) {
			totalPage = totalCount / everyPage;
		} else {
			totalPage = totalCount / everyPage + 1;
		}
		return totalPage;
	}

	/**
	 * 获得起始位置
	 *
	 * @param everyPage
	 *            the every page
	 * @param currentPage
	 *            the current page
	 * @return the begin index
	 */
	public static int getBeginIndex(int everyPage, int currentPage) {
		return (currentPage - 1) * everyPage;
	}

	/**
	 * 获得是否有上一页
	 *
	 * @param currentPage
	 *            the current page
	 * @return the checks for pre page
	 */
	public static boolean getHasPrePage(int currentPage) {
		return currentPage == 1 ? false : true;
	}

	/**
	 * 获得是否有上一页
	 *
	 * @param totalPage
	 *            the total page
	 * @param currentPage
	 *            the current page
	 * @return the checks for next page
	 */
	public static boolean getHasNextPage(int totalPage, int currentPage) {
		return currentPage == totalPage || totalPage == 0 ? false : true;
	}
}

com.laolang.domian.Criticism



package com.laolang.domain;

import java.util.Date;

/**
 * 消息批复类
 * 
 * @author 小代码
 * @version 1.0
 */
public class Criticism {

	/**
	 * Instantiates a new criticism.
	 */
	public Criticism() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Criticism [criticismID=" + criticismID + ", criticismContent="
				+ criticismContent + ", employeeID=" + employeeID
				+ ", criticismTime=" + criticismTime + ", messageID="
				+ messageID + "]";
	}

	/**
	 * Gets the criticism id.
	 *
	 * @return the criticism id
	 */
	public int getCriticismID() {
		return criticismID;
	}

	/**
	 * Sets the criticism id.
	 *
	 * @param criticismID
	 *            the new criticism id
	 */
	public void setCriticismID(int criticismID) {
		this.criticismID = criticismID;
	}

	/**
	 * Gets the criticism content.
	 *
	 * @return the criticism content
	 */
	public String getCriticismContent() {
		return criticismContent;
	}

	/**
	 * Sets the criticism content.
	 *
	 * @param criticismContent
	 *            the new criticism content
	 */
	public void setCriticismContent(String criticismContent) {
		this.criticismContent = criticismContent;
	}

	/**
	 * Gets the employee id.
	 *
	 * @return the employee id
	 */
	public int getEmployeeID() {
		return employeeID;
	}

	/**
	 * Sets the employee id.
	 *
	 * @param employeeID
	 *            the new employee id
	 */
	public void setEmployeeID(int employeeID) {
		this.employeeID = employeeID;
	}

	/**
	 * Gets the criticism time.
	 *
	 * @return the criticism time
	 */
	public Date getCriticismTime() {
		return criticismTime;
	}

	/**
	 * Sets the criticism time.
	 *
	 * @param criticismTime
	 *            the new criticism time
	 */
	public void setCriticismTime(Date criticismTime) {
		this.criticismTime = criticismTime;
	}

	/**
	 * Gets the message id.
	 *
	 * @return the message id
	 */
	public int getMessageID() {
		return messageID;
	}

	/**
	 * Sets the message id.
	 *
	 * @param messageID
	 *            the new message id
	 */
	public void setMessageID(int messageID) {
		this.messageID = messageID;
	}

	/** 批复ID */
	private int criticismID;

	/** 批复内容 */
	private String criticismContent;

	/** 批复人ID */
	private int employeeID;

	/** 批复时间 */
	private Date criticismTime;

	/** 消息ID */
	private int messageID;
}

com.laolang.domain.Employee



package com.laolang.domain;

import java.util.Date;

/**
 * 员工类
 *
 * @author 小代码
 * @version 1.0
 */
public class Employee {

	/**
	 * Gets the employee id.
	 *
	 * @return the employee id
	 */
	public int getEmployeeID() {
		return employeeID;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Employee [employeeID=" + employeeID + ", employeeName="
				+ employeeName + ", employeeSex=" + employeeSex
				+ ", employeeBirth=" + employeeBirth + ", employeePhone="
				+ employeePhone + ", employeePlace=" + employeePlace
				+ ", joinTime=" + joinTime + ", password=" + password
				+ ", isLead=" + isLead + "]";
	}

	/**
	 * Sets the employee id.
	 *
	 * @param employeeID
	 *            the new employee id
	 */
	public void setEmployeeID(int employeeID) {
		this.employeeID = employeeID;
	}

	/**
	 * Gets the employee name.
	 *
	 * @return the employee name
	 */
	public String getEmployeeName() {
		return employeeName;
	}

	/**
	 * Sets the employee name.
	 *
	 * @param employeeName
	 *            the new employee name
	 */
	public void setEmployeeName(String employeeName) {
		this.employeeName = employeeName;
	}

	/**
	 * Checks if is employee sex.
	 *
	 * @return true, if is employee sex
	 */
	public boolean isEmployeeSex() {
		return employeeSex;
	}

	/**
	 * Sets the employee sex.
	 *
	 * @param employeeSex
	 *            the new employee sex
	 */
	public void setEmployeeSex(boolean employeeSex) {
		this.employeeSex = employeeSex;
	}

	/**
	 * Gets the employee birth.
	 *
	 * @return the employee birth
	 */
	public Date getEmployeeBirth() {
		return employeeBirth;
	}

	/**
	 * Sets the employee birth.
	 *
	 * @param employeeBirth
	 *            the new employee birth
	 */
	public void setEmployeeBirth(Date employeeBirth) {
		this.employeeBirth = employeeBirth;
	}

	/**
	 * Gets the employee phone.
	 *
	 * @return the employee phone
	 */
	public String getEmployeePhone() {
		return employeePhone;
	}

	/**
	 * Sets the employee phone.
	 *
	 * @param employeePhone
	 *            the new employee phone
	 */
	public void setEmployeePhone(String employeePhone) {
		this.employeePhone = employeePhone;
	}

	/**
	 * Gets the employee place.
	 *
	 * @return the employee place
	 */
	public String getEmployeePlace() {
		return employeePlace;
	}

	/**
	 * Sets the employee place.
	 *
	 * @param employeePlace
	 *            the new employee place
	 */
	public void setEmployeePlace(String employeePlace) {
		this.employeePlace = employeePlace;
	}

	/**
	 * Gets the join time.
	 *
	 * @return the join time
	 */
	public Date getJoinTime() {
		return joinTime;
	}

	/**
	 * Sets the join time.
	 *
	 * @param joinTime
	 *            the new join time
	 */
	public void setJoinTime(Date joinTime) {
		this.joinTime = joinTime;
	}

	/**
	 * Gets the password.
	 *
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Sets the password.
	 *
	 * @param password
	 *            the new password
	 */
	public void setPassword(String password) {
		this.password = password;
	}


	
	

	public int getIsLead() {
		return isLead;
	}

	public void setIsLead(int isLead) {
		this.isLead = isLead;
	}





	/** 员工编号. */
	private int employeeID;

	/** 员工姓名. */
	private String employeeName;

	/** 员工性别. */
	private boolean employeeSex;

	/** 出生日期. */
	private Date employeeBirth;

	/** 办公室电话. */
	private String employeePhone;

	/** 住址. */
	private String employeePlace;

	/** 录入时间. */
	private Date joinTime;

	/** 系统口令. */
	private String password;

	/** 是否为管理层领导. */
	private int isLead;
}

com.laolang.domain.Message



package com.laolang.domain;
import java.util.Date;

/**
 * 消息类
 * 
 * @author 小代码
 * @version 1.0
 */
public class Message {

	/**
	 * Gets the message id.
	 *
	 * @return the message id
	 */
	public int getMessageID() {
		return messageID;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Message [messageID=" + messageID + ", messageTitle="
				+ messageTitle + ", messageContent=" + messageContent
				+ ", employeeID=" + employeeID + ", publishTime=" + publishTime
				+ "]";
	}

	/**
	 * Sets the message id.
	 *
	 * @param messageID
	 *            the new message id
	 */
	public void setMessageID(int messageID) {
		this.messageID = messageID;
	}

	/**
	 * Gets the message title.
	 *
	 * @return the message title
	 */
	public String getMessageTitle() {
		return messageTitle;
	}

	/**
	 * Sets the message title.
	 *
	 * @param messageTitle
	 *            the new message title
	 */
	public void setMessageTitle(String messageTitle) {
		this.messageTitle = messageTitle;
	}

	/**
	 * Gets the message content.
	 *
	 * @return the message content
	 */
	public String getMessageContent() {
		return messageContent;
	}

	/**
	 * Sets the message content.
	 *
	 * @param messageContent
	 *            the new message content
	 */
	public void setMessageContent(String messageContent) {
		this.messageContent = messageContent;
	}

	/**
	 * Gets the employee id.
	 *
	 * @return the employee id
	 */
	public int getEmployeeID() {
		return employeeID;
	}

	/**
	 * Sets the employee id.
	 *
	 * @param employeeID
	 *            the new employee id
	 */
	public void setEmployeeID(int employeeID) {
		this.employeeID = employeeID;
	}

	/**
	 * Gets the publish time.
	 *
	 * @return the publish time
	 */
	public Date getPublishTime() {
		return publishTime;
	}

	/**
	 * Sets the publish time.
	 *
	 * @param publishTime
	 *            the new publish time
	 */
	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	/** 消息ID */
	private int messageID;

	/** 消息标题 */
	private String messageTitle;

	/** 消息内容 */
	private String messageContent;

	/** 发布人ID */
	private int employeeID;

	/** 发布时间 */
	private Date publishTime;
}

com.laolang.domian.Reply



package com.laolang.domain;

import java.util.Date;

/**
 * 消息回复类
 * 
 * @author 小代码
 * @version 1.0
 * 
 */
public class Reply {

	/**
	 * Instantiates a new reply.
	 */
	public Reply() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Reply [replyID=" + replyID + ", replyContent=" + replyContent
				+ ", employeeID=" + employeeID + ", replyTime=" + replyTime
				+ ", messageID=" + messageID + "]";
	}

	/**
	 * Gets the reply id.
	 *
	 * @return the reply id
	 */
	public int getReplyID() {
		return replyID;
	}

	/**
	 * Sets the reply id.
	 *
	 * @param replyID
	 *            the new reply id
	 */
	public void setReplyID(int replyID) {
		this.replyID = replyID;
	}

	/**
	 * Gets the reply content.
	 *
	 * @return the reply content
	 */
	public String getReplyContent() {
		return replyContent;
	}

	/**
	 * Sets the reply content.
	 *
	 * @param replyContent
	 *            the new reply content
	 */
	public void setReplyContent(String replyContent) {
		this.replyContent = replyContent;
	}

	/**
	 * Gets the employee id.
	 *
	 * @return the employee id
	 */
	public int getEmployeeID() {
		return employeeID;
	}

	/**
	 * Sets the employee id.
	 *
	 * @param employeeID
	 *            the new employee id
	 */
	public void setEmployeeID(int employeeID) {
		this.employeeID = employeeID;
	}

	/**
	 * Gets the reply time.
	 *
	 * @return the reply time
	 */
	public Date getReplyTime() {
		return replyTime;
	}

	/**
	 * Sets the reply time.
	 *
	 * @param replyTime
	 *            the new reply time
	 */
	public void setReplyTime(Date replyTime) {
		this.replyTime = replyTime;
	}

	/**
	 * Gets the message id.
	 *
	 * @return the message id
	 */
	public int getMessageID() {
		return messageID;
	}

	/**
	 * Sets the message id.
	 *
	 * @param messageID
	 *            the new message id
	 */
	public void setMessageID(int messageID) {
		this.messageID = messageID;
	}

	/** 回复ID */
	private int replyID;

	/** 回复内容 */
	private String replyContent;//

	/** 回复人ID */
	private int employeeID; //

	/** 回复时间 */
	private Date replyTime; //

	/** 消息ID */
	private int messageID; //
}

com.laolang.filter.CharsetEncodingFilter



package com.laolang.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Servlet Filter implementation class CharsetEncodingFilter
 * 将所有页面的字符集过滤为utf-8
 * @version 1.2.1
 * @author 小代码
 */
public class CharsetEncodingFilter implements Filter {

	/**
	 * Default constructor.
	 */
	public CharsetEncodingFilter() {
	}

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// place your code here

		// pass the request along the filter chain
		request.setCharacterEncoding(CODE);
		response.setCharacterEncoding(CODE);
		chain.doFilter(request, response);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		CODE = fConfig.getInitParameter("code");
	}

	private static String CODE = "UTF-8";

}

com.laolang.servlet.CriticismServlet



package com.laolang.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.CriticismDao;
import com.laolang.daoImpl.CriticismDaoImpl;
import com.laolang.domain.Criticism;
import com.laolang.domain.Employee;

/**
 * Servlet implementation class CriticismServlet
 */
public class CriticismServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CriticismServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//获取批复内容
		String criContent = request.getParameter("critisim_input");
		
		int messageID = Integer.parseInt(request.getParameter("messageID"));
		ServletContext context = getServletContext();
		RequestDispatcher dispatcher = null;

		Employee emp = (Employee) request.getSession().getAttribute("employee");
		Criticism cri = new Criticism();
		//如果未登陆,则提示其登陆
		if (null == emp) {
			request.setAttribute("criticismError", "进行批复前请登陆 ");
		} else {
			//如果未输入批复内容,则批复其输入批复内容
			if (null == criContent || criContent.equals("")) {
				request.setAttribute("criticismError", "进行输入批复内容");
			} else {
				//创建批复对象
				
				cri.setCriticismContent(criContent);
				cri.setEmployeeID(emp.getEmployeeID());
				cri.setMessageID(messageID);
				cri.setCriticismTime(new Date());

				//将批复插入数据库中
				CriticismDao criDao = new CriticismDaoImpl();
				try {
					criDao.insertCriticism(cri);
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		dispatcher = context
				.getRequestDispatcher("/MessageContentServlet?messageID="
						+ messageID);
		dispatcher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

com.laolang.servlet.loginServlet



package com.laolang.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.EmployeeDao;
import com.laolang.daoImpl.EmployeeDaoImpl;
import com.laolang.domain.Employee;

/**
 * Servlet implementation class loginServlet
 * 登陆验证
 * @version 1.2.1
 * @author 小代码
 */
public class loginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public loginServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//得到用户输入的编号和密码
		String userID = request.getParameter("userID");
		String userPwd = request.getParameter("userPwd");
		int id = Integer.parseInt(userID);
		
		Employee emp = null;
		EmployeeDao dao = new EmployeeDaoImpl();
		ServletContext servletContext = getServletContext();
		RequestDispatcher dispatcher = null;
		
		try {
			//查询数据库
			emp = dao.selectById(id);
			
			//如果不存在该员工,则返回登陆页面并提示
			if( null == emp ){
				request.setAttribute("loginError", "该员工编号不存在");//员工编号不存在,则跳回登陆页面
				dispatcher = servletContext.getRequestDispatcher("/login.jsp");
			}else if( !userPwd.equals(emp.getPassword())){//如果密码不正确,则返回登陆页面并提示
				request.setAttribute("loginError", "登陆密码不正确");
				dispatcher = servletContext.getRequestDispatcher("/login.jsp");
			}else{ //ID和密码都正确,则跳到首页
				request.getSession().setAttribute("employee", emp);
				response.sendRedirect("index.jsp");
				return ;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		//页面跳转
		dispatcher.forward(request, response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet( request,response);
	}

}

com.laolang.dao.MessageContentServlet



package com.laolang.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.CriticismDao;
import com.laolang.dao.MessageDao;
import com.laolang.dao.ReplyDao;
import com.laolang.daoImpl.CriticismDaoImpl;
import com.laolang.daoImpl.MessageDaoImpl;
import com.laolang.daoImpl.ReplyDaoImpl;
import com.laolang.db.Page;
import com.laolang.db.PageUtil;
import com.laolang.domain.Criticism;
import com.laolang.domain.Message;
import com.laolang.domain.Reply;

/**
 * Servlet implementation class MessageContentServlet
 */
public class MessageContentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public MessageContentServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// 得到要查看的消息的ID
		int messageID = Integer.parseInt(request.getParameter("messageID"));

		// 查询消息
		MessageDao dao = new MessageDaoImpl();
		Message message = dao.selectMessageById(messageID);

		// 将消息保存到request
		request.setAttribute("message", message);

		// 查询当前消息对应的所有回复
			//当前在第几页
		int currentPage = 0;
		String currentPageStr = request.getParameter("currentPage");

		if (null == currentPageStr || currentPageStr.equals("")) {
			currentPage = 1;
		} else {
			currentPage = Integer.parseInt(currentPageStr);
		}
		
		
		try {
			//查询回复
			ReplyDao replyDao = new ReplyDaoImpl();
			Page page = PageUtil.createPage(5, replyDao.selectReplyCountByMessageId(messageID), currentPage);
			List replyList = replyDao.selectReplyByMesageId(messageID, page);
			
			//将回复保存到request
			request.setAttribute("replyList", replyList);
			request.setAttribute("page", page);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		

		//查询当前消息对应的批复
		try {
			CriticismDao criDao = new CriticismDaoImpl();
			Criticism criticism = criDao.selectCriticismByMessageId(messageID);
			request.setAttribute("criticism", criticism);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		//页面跳转
		ServletContext context = getServletContext();
		RequestDispatcher dispatcher = context.getRequestDispatcher("/showMessage.jsp");
		dispatcher.forward(request, response);
		

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

com.laolang.servlet.MessageListServlet



package com.laolang.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.MessageDao;
import com.laolang.daoImpl.MessageDaoImpl;
import com.laolang.db.Page;
import com.laolang.db.PageUtil;
import com.laolang.domain.Message;

/**
 * Servlet implementation class MessageListServlet
 */
public class MessageListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public MessageListServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// 当前页数
		int currentPage = 0;
		String currentPageStr = request.getParameter("currentPage");// 获得当前页数
		if (null == currentPageStr || currentPageStr.equals("")) {// 如果不存在,则赋值为 1
			currentPage = 1;
		} else {
			currentPage = Integer.parseInt(currentPageStr);
		}
		
		//查询要显示的那一页
		MessageDao dao = new MessageDaoImpl();
		Page page = PageUtil.createPage(5, dao.selectMessageCount(), currentPage);
		List messageList = dao.selectMesssageAll(page);
		
		//将查询结果保存到request
		request.setAttribute("messageList", messageList);
		request.setAttribute("page", page);
		
		//页面跳转
		ServletContext context = getServletContext();
		RequestDispatcher dispatcher = context.getRequestDispatcher("/messageList.jsp");
		dispatcher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

com.laolang.servlet.PublishNewMessageServlet



package com.laolang.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.MessageDao;
import com.laolang.daoImpl.MessageDaoImpl;
import com.laolang.domain.Employee;
import com.laolang.domain.Message;

/**
 * 发布消息处理
 * 
 * @author 小代码
 * @version 1.0
 */
public class PublishNewMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PublishNewMessageServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext context = getServletContext();
		RequestDispatcher dispatcher = null;
		
		//获取员工输入的消息标题和内容
		String messageTitle = request.getParameter("messageTitle");
		String messageContext = request.getParameter("messageContent");
		
		//确定是哪个员工发布消息
		Employee emp = (Employee)request.getSession().getAttribute("employee");
		
		if( null == emp ){//如果员工未登陆,则跳回消息发布页面,并提示其进行登陆
			request.setAttribute("publishNewMessageError", "发布消息前必须进行身份识别");
			dispatcher = context.getRequestDispatcher("/publishNewMessage.jsp");
		}else{
			if( null == messageTitle || messageTitle.equals("")){//如果员工未输入消息,则跳回消息发布页面,并提示其输入标题
				request.setAttribute("publishNewMessageError", "请输入标题");
				dispatcher = context.getRequestDispatcher("/publishNewMessage.jsp");
			}else{
				//创建消息对象
				Message message = new Message();
				message.setMessageTitle(messageTitle);
				message.setMessageContent(messageContext);
				message.setPublishTime(new Date());
				message.setEmployeeID(emp.getEmployeeID());
				
				//插入数据库
				MessageDao dao = new MessageDaoImpl();
				dao.insertMessage(message);
				
				//跳转到消息列表的 servlet
				dispatcher = context.getRequestDispatcher("/MessageListServlet");
				
			}
		}
		
		dispatcher.forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

com.laolang.servlet.ReplyServlet



package com.laolang.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.laolang.dao.ReplyDao;
import com.laolang.daoImpl.ReplyDaoImpl;
import com.laolang.domain.Employee;
import com.laolang.domain.Reply;

/**
 * Servlet implementation class ReplyServlet
 */
public class ReplyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ReplyServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// 获取回复内容
		String replyContent = request.getParameter("replyContent");
		int messageID = Integer.parseInt(request.getParameter("messageID"));
		ServletContext context = getServletContext();
		RequestDispatcher dispatcher = null;

		// 从session中获取员工对象
		Employee emp = (Employee) request.getSession().getAttribute("employee");

		// 如果未登陆
		if (null == emp) {
			request.setAttribute("replyError", "发布回复前必须先进行身份识别");
		} else {
			if (null == replyContent || replyContent.equals("")) {// 如果回复内容为空,则提示其输入回复内容
				request.setAttribute("replyNoContentError", "发布回复前必须先进行身份识别");
			} else {
				// 创建回复对象
				Reply reply = new Reply();
				reply.setEmployeeID(emp.getEmployeeID());
				reply.setReplyContent(replyContent);
				reply.setMessageID(messageID);
				reply.setReplyTime(new Date());

				// 将回复内容插入数据库
				ReplyDao dao = new ReplyDaoImpl();
				try {
					dao.insertReply(reply);
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		dispatcher = context.getRequestDispatcher("/MessageContentServlet?messageID="+ messageID);
		dispatcher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}


jsp页面代码

目录结构


D:\program\java\tomcat\tomcat7\webapps\jc\jc_my_1_1\WebContent>tree /f
卷 软件 的文件夹 PATH 列表
卷序列号为 0006-17B7
D:.
│  index.jsp
│  login.jsp
│  messageList.jsp
│  publishNewMessage.jsp
│  showMessage.jsp
│
├─ckeditor
│  ...
│
├─css
│      content.css
│      layout.css
│
├─images
│      logo.png
│
├─js
│      jquery-1.10.1.js
│      myjs.js
│
├─META-INF
│      MANIFEST.MF
│
└─WEB-INF
    │  web.xml
    │
    └─lib
            commons-dbutils-1.5.jar
            jstl.jar
            mysql-connector-java-5.1.28-bin.jar
            standard.jar


D:\program\java\tomcat\tomcat7\webapps\jc\jc_my_1_1\WebContent>




index.jsp


<%@page import="com.laolang.domain.Message"%>
<%@page import="java.util.List"%>
<%@page import="com.laolang.db.Page"%>
<%@page import="com.laolang.db.PageUtil"%>
<%@page import="com.laolang.daoImpl.MessageDaoImpl"%>
<%@page import="com.laolang.dao.MessageDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




企业日常事务管理系统-首页




	
	
	

员工信息

没有身份识别
  • 员工编号:${employee.employeeID }
  • 员工姓名:${employee.employeeName }
  • 员工性别:${employee.employeeSex ? "男" : "女"}
  • 出生日期:${employee.employeeBirth }
  • 办公室电话:${employee.employeePhone }
  • 员工住址:${employee.employeePlace }
  • 是否管理层领导:${employee.isLead == 1 ? '是' : '否'}

最新消息

<% MessageDao dao = new MessageDaoImpl(); Page pageX = PageUtil.createPage(5, dao.selectMessageCount(), 1); List messageList = dao.selectMesssageAll(pageX); for( Message message : messageList){ %>

<%=message.getMessageTitle()%>     <%=message.getPublishTime()%>

<% } %>


login.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




企业日常事务管理系统-身份识别






	
	


messageList.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




企业日常事务管理系统-消息列表




	
	

>>${message.messageTitle }

发布人ID:${message.employeeID }  发布时间:${message.publishTime }


首页 | 上一页 | 首页|上一页 下一页 | 尾页 下一页|尾页 当前为第${page.currentPage}页,共${page.totalPage}页


publishNeweMessage.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




企业日常事务管理系统-发布新消息









	
	

${requestScope.publishNewMessageError}

消息标题:
消息内容:


showMessage.jsp



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




企业日常事务管理系统-查看具体消息









	

${message.messageTitle}


${message.messageContent}
领导批复:${empty criticism ? "暂无" : criticism.criticismContent }

${reply.replyContent }
回复人ID:${reply.employeeID } 回复时间:${reply.replyTime }

${stat.index }

回复:

${requestScope.replyError }

${requestScope.replyNoContentError }


${criticismError }

批复:



css/layout.css



@CHARSET "UTF-8";
/* 布局CSS */
/*
CSS初始化
*/
*{
	margin: 0;
	padding: 0;
	border: 0;
}


/* 总容器 */
.container{
	width:960px;
	margin:0 auto;
}

/* 横向空白分隔条 */
.empty_bar{
	width:100%;
	height:10px;
	float:left;
	clear:both;
}

/* 分页 */
.pages{
	text-align: center;
	margin-top: 20px;
}


/* 头部 */
.header{
	width:100%;
	float:left;
}

/* 网站logo */
.logo{
	width:120px;
	height:100px;
	float:left;
	background:green;
}

/* 广告位 */
.banner{
	width:830px;
	height:100px;
	float:right;
	background:yellow;
}

/* 导航菜单 */
.nav{
	width:100%;
	height:40px;
	float:left;
	background:#f2eada;
}


/* 内容容器 */
.content{
	width:100%;
	float:left;
}

.content_messageList{
	width:958px;
	height: 368px;
	border: 1px solid #aaa;
}

/* 标题 */
.tit{
	width:100%;
	height:30px;
	float:left;
	background:#f2eada;
}

/* 员工信息 */
.employeeinfo{
	width:330px;
	float:left;
}

/* 信息 */
.info{
	width:328px;
	height:370px;
	float:left;
	border:1px solid #aaa;
}

/* 最新消息列表 */
.messagelist{
	width:620px;
	float:right;
}

/* 消息列表 */
.list{
	width:617px;
	height:370px;
	float:right;
	border:1px solid #aaa;
}



/* 版权信息 */
.footer{
	width:958px;
	height:60px;
	float:left;
	border:1px solid #AAB6CC;
}


css/content.css



@CHARSET "UTF-8";

.nav ul li {
	list-style: none;
	text-align: center;
	line-height: 40px;
	margin-left: 20px;
	float: left;
}

.nav a {
	text-decoration: none;
}

.nav .li_space {
	width: 1px;
	background: green;
	height: 20px;
	margin-top: 10px;
	float: left;
}

/* 标题字体 */
.tit h3 {
	font-size: 14px;
	margin-left: 20px;
	line-height: 30px;
}

/* 员工信息列表样式 */
.info ul li {
	list-style: none;
	margin-left: 20px;
	margin-top: 10px;
}

/* 消息标题样式 */
.list p {
	margin-left: 20px;
	margin-top: 20px;
}

.list a {
	text-decoration: none;
}

/*消息列表页消息标题样式*/
.list_tit {
	margin-left: 20px;
	margin-top: 20px;
}

.list_tit a {
	text-decoration: none;
}

/* 消息列表页 下划线样式 */
.content_messageList hr {
	height: 1px;
	border: none;
	border-top: 1px dashed #185598;
}

/* 消息列表页 发布时间样式 */
.list_id_time {
	text-align: right;
	color: #CCCCCC;
	font-size: 14px;
}

/* 消息发布时间样式 */
.list span {
	color: #CCCCCC;
	font-size: 14px;
}

/* 显示消息下划线 */
.content hr {
	height: 1px;
	border: none;
	border-top: 1px dashed #185598;
}

/* 发布新消息页表单样式 */
.newmessage {
	height: 100%;
	width: 60%;
	float: left;
	margin-left: 20%;
}

.newmessage .newmessage_submit {
	float: right;
}

.login {
	height: 100%;
	width: 60%;
	float: left;
	margin-left: 20%;
}

/* 版权信息样式 */
.footer ul li {
	list-style: none;
	text-align: center;
	line-height: 60px;
}


js/myjs.js



/**
 * 
 */
$(document).ready(function() {
	$(".text_login").focus(function() {
		if ($(this).val() == 'employee id' || $(this).val() == 'password') {
			$(this).val('');
		}
		if ($(this).attr('id') == 'user_pwd1') {
			$(this).hide();
			$('#user_pwd').show();
			$('#user_pwd').focus();
		}
	});
	$(".text_login").blur(function() {
		if ($(this).attr('id') == 'user_pwd' && $(this).val() == '') {
			$(this).hide();
			$('#user_pwd1').show();
			$('#user_pwd1').val('password');
		} else if ($(this).attr('id') == 'user_id' && $(this).val() == '') {
			$(this).val('employee id');
		}
	});
});



五、运行效果

首页:

未登陆时

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第2张图片

登陆后:

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第3张图片


身份识别

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第4张图片


消息列表

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第5张图片


发布新消息

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第6张图片


查看具体消息内容

Java Web项目开发案例精粹-1-企业日常事务管理系统-源代码_第7张图片

转载于:https://my.oschina.net/iamhere/blog/492925

你可能感兴趣的:(java,数据库,web.xml)