package com.yxq.servlet;
import java.io.IOException;
import java.io.PrintWriter;
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 javax.servlet.http.HttpSession;
import com.yxq.dao.ArticleDao;
import com.yxq.dao.ArticleTypeDao;
import com.yxq.dao.ReviewDao;
import com.yxq.toolsbean.MyTools;
import com.yxq.valuebean.ArticleBean;
import com.yxq.valuebean.ArticleTypeBean;
import com.yxq.valuebean.ReviewBean;
public class ArticleServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter("action");
if(action==null)
action="";
if (action.equals("select"))
this.selectArticle(request, response); //获取某类别下所有文章
if (action.equals("adminSelectList"))
this.adminSelectList(request,response);
if (action.equals("adminSelectSingle"))
this.adminSelectSingle(request,response);
if (action.equals("add"))
this.addArticle(request, response); //增加文章
if (action.equals("delete"))
this.deleteArticle(request, response); //删除文章
if (action.equals("modify"))
this.modifyArticle(request, response); //修改文章
if (action.equals("read"))
this.readArticle(request, response); //阅读文章
if (action.equals("followAdd"))
this.validateFollow(request, response); //发表文章回复
if (action.equals("typeAdd"))
this.addArticleType(request, response); //增加文章类别
if (action.equals("typeSelect"))
this.selectArticleType(request, response); //查看文章类别
if (action.equals("typeModify"))
this.modifyArticleType(request, response); //修改文章类别
if (action.equals("typeDelete"))
this.deleteArticleType(request, response); //删除文章类别
}
/**
* @功能 验证评论信息
*/
public void validateFollow(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
boolean mark=true;
String messages="";
String content=request.getParameter("reContent");
if(content==null||content.equals("")){
mark=false;
messages="<li>请输入 <b>评论内容!</b></li>";
}
if(mark){
content=MyTools.toChinese(content);
if(content.length()>1000){
mark=false;
messages="<li><b>评论内容</b> 最多允许输入1000个字符!</li>";
}
}
if(!mark){
request.setAttribute("messages",messages);
RequestDispatcher rd=request.getRequestDispatcher("/front/article/error.jsp");
rd.forward(request,response);
}
else{
followAdd(request,response);
}
}
/**
* @功能 添加文章评论
*/
public void followAdd(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
int id=Integer.parseInt(request.getParameter("articleId"));
String author=MyTools.toChinese(request.getParameter("reAuthor"));
String content=MyTools.toChinese(request.getParameter("reContent"));
String today=MyTools.changeTime(new Date());
if(author==null||author.equals(""))
author="匿名好友";
ReviewBean reviewBean = new ReviewBean();
reviewBean.setArticleId(id);
reviewBean.setReAuthor(author);
reviewBean.setReContent(content);
reviewBean.setReSdTime(today);
ReviewDao reviewDao = new ReviewDao();
String messages="";
String forward="";
boolean mark=reviewDao.operationReview("add",reviewBean);
if (mark) {
forward="/front/article/success.jsp";
messages="<li>发表评论成功!</li>";
} else {
forward="/front/article/error.jsp";
messages="<li>发表评论失败!</li>";
}
request.setAttribute("messages",messages);
RequestDispatcher rd=request.getRequestDispatcher(forward);
rd.forward(request,response);
}
/**
* @功能 阅读文章
* @实现 1.增加文章阅读次数<br>2.获取指定文章信息<br>3.获取对该文章的所有评论
*/
public void readArticle(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
ArticleBean articleBean = new ArticleBean();
ArticleDao articleDao = new ArticleDao();
ReviewDao reviewDao=new ReviewDao();
String strId=request.getParameter("id");
int id=MyTools.strToint(strId);
articleBean.setId(id);
articleDao.operationArticle("readTimes", articleBean); //累加阅读次数
articleBean=articleDao.queryArticleSingle(id); //查询指定文章的详细内容
session.setAttribute("readSingle", articleBean); //保存articleBean到request对象中
List reviewlist=reviewDao.queryReview(id);
session.setAttribute("reviewlist",reviewlist);
RequestDispatcher rd = request.getRequestDispatcher("/front/article/ArticleSingle.jsp");
rd.forward(request, response);
}
/**
* @功能 修改文章
*/
public void modifyArticle(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
RequestDispatcher rd=null;
ArticleDao articleDao=new ArticleDao();
String type=request.getParameter("type");
if(type==null)
type="";
if(!type.equals("doModify")){
int id=MyTools.strToint(request.getParameter("id"));
ArticleBean articleBean=articleDao.queryArticleSingle(id);
request.setAttribute("modifySingle",articleBean);
rd=request.getRequestDispatcher("/admin/article/ArticleModify.jsp");
rd.forward(request,response);
}
else{
String messages="";
String href="";
String forward="";
boolean flag=validateArticle(request,response);
if(flag){
ArticleBean articleBean = new ArticleBean();
articleBean.setId(MyTools.strToint(request.getParameter("id")));
articleBean.setTypeId(Integer.valueOf(request.getParameter("typeId")));
articleBean.setTitle(MyTools.toChinese(request.getParameter("title")));
articleBean.setCreate(MyTools.toChinese(request.getParameter("create")));
articleBean.setInfo(MyTools.toChinese(request.getParameter("info")));
articleBean.setContent(MyTools.toChinese(request.getParameter("content")));
boolean mark=articleDao.operationArticle("modify",articleBean);
if (mark) {
messages="<li>修改成功!</li>";
href="<a href='ArticleServlet?action=adminSelectList&typeId="+session.getAttribute("showTypeId")+"'>[继续修改其他文章]</a>";
forward="/admin/success.jsp";
} else {
messages="<li>修改失败!</li>";
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
}
request.setAttribute("messages",messages);
request.setAttribute("href",href);
}
else{
href="<a href='javascript:window.history.go(-1)>[返回]</a>";
forward="/admin/error.jsp";
request.setAttribute("href",href);
}
rd=request.getRequestDispatcher(forward);
rd.forward(request,response);
}
}
/**
* @功能 后台-删除文章
*/
public void deleteArticle(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
ArticleDao articleDao = new ArticleDao();
ArticleBean articleBean = new ArticleBean();
String messages="";
String href="";
String forward="";
articleBean.setId(MyTools.strToint(request.getParameter("id")));
boolean mark=articleDao.operationArticle("delete", articleBean);
if (mark) {
String typeId=request.getParameter("typeId");
messages+="<li>删除文章成功!</li>";
href="<a href='ArticleServlet?action=adminSelectList&typeId="+typeId+"'>[继续删除其他文章]</a>";
forward="/ad
没有合适的资源?快使用搜索试试~ 我知道了~
MyBlog JSP博客程序MSSQL版
共125个文件
jsp:45个
jpg:23个
java:22个
4星 · 超过85%的资源 需积分: 3 54 下载量 150 浏览量
2009-07-18
18:30:44
上传
评论 2
收藏 1.03MB RAR 举报
温馨提示
MyBlog JSP博客程序MSSQL版MyBlog JSP博客程序MSSQL版MyBlog JSP博客程序MSSQL版MyBlog JSP博客程序MSSQL版MyBlog JSP博客程序MSSQL版MyBlog JSP博客程序MSSQL版
资源推荐
资源详情
资源评论
收起资源包目录
MyBlog JSP博客程序MSSQL版 (125个子文件)
DB.java.bak 3KB
ArticleServlet.class 14KB
PhotoServlet.class 7KB
FriendServlet.class 7KB
WordServlet.class 5KB
ArticleDao.class 4KB
LogXServlet.class 4KB
FriendDao.class 3KB
PhotoDao.class 3KB
DB.class 3KB
ArticleTypeDao.class 3KB
ArticleBean.class 3KB
IndexServlet.class 3KB
WordDao.class 2KB
ReviewDao.class 2KB
LogonDao.class 2KB
WordBean.class 2KB
MyTools.class 2KB
ReviewBean.class 1KB
FriendBean.class 1KB
PhotoBean.class 1KB
MasterBean.class 1KB
ArticleTypeBean.class 994B
style_admin.css 2KB
style.css 948B
Thumbs.db 29KB
程序使用说明书.doc 285KB
msbase.jar 280KB
mssqlserver.jar 66KB
msutil.jar 58KB
MyjspSmartUpload.jar 16KB
ArticleServlet.java 18KB
FriendServlet.java 9KB
PhotoServlet.java 7KB
WordServlet.java 5KB
ArticleDao.java 4KB
LogXServlet.java 3KB
DB.java 3KB
FriendDao.java 2KB
IndexServlet.java 2KB
PhotoDao.java 2KB
ArticleTypeDao.java 2KB
WordDao.java 2KB
ArticleBean.java 2KB
MyTools.java 2KB
ReviewDao.java 1KB
LogonDao.java 1KB
WordBean.java 1010B
ReviewBean.java 836B
MasterBean.java 757B
FriendBean.java 716B
PhotoBean.java 686B
ArticleTypeBean.java 509B
logonBG.jpg 74KB
admin_top.jpg 69KB
top.jpg 66KB
adminLmenu_1.jpg 22KB
adminLmenu_2.jpg 21KB
bg.jpg 19KB
admin_sonTop.jpg 17KB
btn_bg.jpg 14KB
women.jpg 14KB
hand.jpg 14KB
man.jpg 13KB
end.jpg 4KB
main_B.jpg 3KB
left_T.jpg 1KB
line.jpg 1KB
left_M.jpg 955B
friend.jpg 698B
left_E.jpg 619B
more.jpg 601B
ico2.jpg 481B
ico3.jpg 444B
ico4.jpg 404B
ico1.jpg 389B
FrontLeft.jsp 6KB
ArticleSingle.jsp 5KB
ArticleModify.jsp 4KB
FrontIndex.jsp 4KB
ArticleList.jsp 4KB
ArticleList.jsp 3KB
WordShow.jsp 3KB
ArticleAdd.jsp 3KB
AdminLeft.jsp 3KB
FriendModify.jsp 3KB
PhotoList.jsp 2KB
WordList.jsp 2KB
FriendList.jsp 2KB
FriendList.jsp 2KB
PhotoList.jsp 2KB
FriendAdd.jsp 2KB
ArticleSingle.jsp 2KB
ArticleTypeModify.jsp 2KB
FriendSingle.jsp 2KB
ArticleTypeList.jsp 2KB
FriendSingle.jsp 2KB
ArticleIndex.jsp 2KB
ArticleTypeAdd.jsp 2KB
PhotoUpload.jsp 2KB
共 125 条
- 1
- 2
资源评论
- hjjfdyhg2015-03-30这个JSP博客系统很好用,做的很好
茶陵快乐宝贝
- 粉丝: 4
- 资源: 221
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Spring Boot + Vue 3.2 + Vite 4.3开发的前后端分离博客项目源代码.zip
- Go语言基础知识到高级应用全面解析
- 毕业设计前后端分离博客项目源代码.zip
- E008 库洛米(3页).zip
- 前端拿到的列表数据里id都一样的处理办法.txt
- 批量导出多项目核心目录工具
- 课程设计前后端分离博客项目源代码.zip
- C#语言教程:面向对象与高级编程技术全面指南
- PHP语言详细教程:从基础到实战
- 电影管理系统,数据库系统概论大作业
- Web开发中JavaScript编程语言的全面解析
- ajax发请求示例.txt
- 企业数据管理系统项目源代码.zip
- 计算机技术-JAVA语言介绍-基本语法(上)
- 基于西门子 PLC 的晶圆研磨机自动控制系统设计与实现-论文
- 家庭理财系统源代码+答辩PPT+论文.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功