package com.ns.controller;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ns.bean.NoticeBean;
import com.ns.dao.NoticeDao;
public class NoticeServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
int pageSize=10;
String method=req.getParameter("method");
String title=req.getParameter("title");
String content=req.getParameter("content");
String publisher="";
String username="";
Date publishTime=null;
NoticeBean notice=new NoticeBean();
NoticeDao noticeDao=new NoticeDao();
List<NoticeBean> notices=new ArrayList<NoticeBean>();
RequestDispatcher rd;
//增加公告信息开始
if(method.equals("add")){
System.out.println("开始添加。。。");
notice=new NoticeBean();
publisher=(String)req.getSession().getAttribute("username");
publishTime=new Date();
notice.setTitle(title);
notice.setContent(content);
notice.setPublisher(publisher);
notice.setPublishTime(publishTime);
try{
noticeDao.addNotice(notice);
req.setAttribute("method", "addnotice");
rd=req.getRequestDispatcher("/success.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}//增加公告信息结束
else if(method.equals("modifyall")){
int nowPage=Integer.parseInt(req.getParameter("nowPage"));
int recordNum=0;
int pageNum=0;
username=(String)req.getSession().getAttribute("username");
try{
recordNum=noticeDao.getAllNotice(username);
if((recordNum%pageSize)!=0){
pageNum=(recordNum/pageSize)+1;
}else{
pageNum=recordNum/pageSize;
}
if(nowPage<=0){
nowPage=1;
}else if(nowPage>pageNum){
nowPage=pageNum;
}
notices=noticeDao.getAllNotice(nowPage,pageSize,username);
req.setAttribute("pageNum", pageNum);
req.getSession().setAttribute("notices", notices);
req.setAttribute("nowPage", nowPage);
rd=req.getRequestDispatcher("/admin_modnotice.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}
else if(method.equals("modifyone")){
int id=Integer.parseInt(req.getParameter("id"));
try{
notice=noticeDao.getNoticeById(id);
req.setAttribute("notice", notice);
rd=req.getRequestDispatcher("/admin_modone.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}
//修改公告信息开始
else if(method.equals("modify")){
int id=Integer.parseInt(req.getParameter("id"));
publishTime=new Date();
notice=new NoticeBean();
notice.setId(id);
notice.setTitle(title);
notice.setContent(content);
notice.setPublishTime(publishTime);
try{
noticeDao.modifyNotice(notice);
req.setAttribute("method", "modnotice");
rd=req.getRequestDispatcher("/success.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}//修改公告信息结束
//查询所有公告信息开始
else if(method.equals("selectall")){
int nowPage=Integer.parseInt(req.getParameter("nowPage"));
int recordNum=0;
int pageNum=0;
try{
recordNum=noticeDao.getAllNotice();
if((recordNum%pageSize)!=0){
pageNum=(recordNum/pageSize)+1;
}else{
pageNum=recordNum/pageSize;
}
if(nowPage<=0){
nowPage=1;
}else if(nowPage>pageNum){
nowPage=pageNum;
}
notices=noticeDao.getAllNotice(nowPage,pageSize);
req.setAttribute("pageNum", pageNum);
req.getSession().setAttribute("notices", notices);
req.setAttribute("nowPage", nowPage);
rd=req.getRequestDispatcher("/common_notices.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}//查询所有公告信息结束
//查询部分公告信息开始
else if(method.equals("selectsome")){
int nowPage=Integer.parseInt(req.getParameter("nowPage"));
int recordNum=0;
int pageNum=0;
username=(String)req.getSession().getAttribute("username");
try{
recordNum=noticeDao.getAllNotice(username);
if((recordNum%pageSize)!=0){
pageNum=(recordNum/pageSize)+1;
}else{
pageNum=recordNum/pageSize;
}
if(nowPage<=0){
nowPage=1;
}else if(nowPage>pageNum){
nowPage=pageNum;
}
notices=noticeDao.getAllNotice(nowPage,pageSize,username);
req.setAttribute("pageNum", pageNum);
req.getSession().setAttribute("notices", notices);
req.setAttribute("nowPage", nowPage);
rd=req.getRequestDispatcher("/admin_notices.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}//查询部分公告信息结束
//查看公告信息的具体内容开始
else if(method.equals("selectone")){
int id=Integer.parseInt(req.getParameter("id"));
try{
notice=noticeDao.getNoticeById(id);
req.setAttribute("notice", notice);
rd=req.getRequestDispatcher("/singlenotice.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}//查看公告信息的具体内容结束
else if(method.equals("deleteall")){
int nowPage=Integer.parseInt(req.getParameter("nowPage"));
int recordNum=0;
int pageNum=0;
username=(String)req.getSession().getAttribute("username");
try{
recordNum=noticeDao.getAllNotice(username);
if((recordNum%pageSize)!=0){
pageNum=(recordNum/pageSize)+1;
}else{
pageNum=recordNum/pageSize;
}
if(nowPage<=0){
nowPage=1;
}else if(nowPage>pageNum){
nowPage=pageNum;
}
notices=noticeDao.getAllNotice(nowPage,pageSize,username);
req.setAttribute("pageNum", pageNum);
req.getSession().setAttribute("notices", notices);
req.setAttribute("nowPage", nowPage);
rd=req.getRequestDispatcher("/admin_delnotice.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}
else if(method.equals("delete")){
int id=Integer.parseInt(req.getParameter("id"));
try{
noticeDao.deleteNoticeById(id);
req.setAttribute("method", "delnotice");
rd=req.getRequestDispatcher("/success.jsp");
rd.forward(req, resp);
}catch(SQLException e){
rd=req.getRequestDispatcher("/failure.jsp");
rd.forward(req, resp);
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
共 275 条
- 1
- 2
- 3
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- silence2011162016-09-26挺好用的,非常满意
- sandy13145202015-04-16挺好的,对我不太实用
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
chinashaoshengjie
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 城市鎏金风素材PPT.pptx
- 305建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\水1TJ-卫生间大样031020.dwg
- 305建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\水1-C型平面031014.dwg
- 305建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\水1-C型平面(改).dwg
- 建筑结构水电欧式6套(14.5x20.2)\施工图\C型施工图\煤气-2dy.dwg
- 基于Python语言和pygame库开发了一款名为“接金币”的休闲游戏
- MATLAB用户指南或参考手册
- H.264视频流解析工具
- 305建筑结构水电欧式6套(14.5x20.2)\施工设计说明-02.dwg
- 高代大作业-矩阵在图像几何变换中的应用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)