Java项目-Javaweb实现个人博客

作者主页:编程指南针

 简介:Java领域优质创作者、CSDN博客专家  Java项目、简历模板、学习资料、面试题库、技术互助

文末获取源码 

项目编号 :KS020

运行环境:

开发工具:IDEA /ECLIPSE

应用服务器:TOMCAT8

JDK:1.7

MYSQL:5.7

开发技术:

JSP/SERVLET/JDBC

项目运行截图:

以上是基于JSP实现个人博客的部分功能展示,本系统功能相对完整,比较适合做课程设计或期未作业使用。、

核心代码如下:

package com.wy.webiter;

import java.io.IOException;
import java.io.PrintWriter;

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.wy.dao.ArticleDao;
import com.wy.dao.ArticleTypeDao;
import com.wy.dao.RestoreDao;
import com.wy.form.ArticleForm;
import com.wy.form.ArticleTypeForm;
import com.wy.form.RestoreForm;
import com.wy.tool.Chinese;

public class ArticleServlet extends HttpServlet {

	private ArticleDao articleDao = null;

	private ArticleTypeDao articleTypeDao = null;

	private RestoreDao restoreDao = null;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int method = Integer.parseInt(request.getParameter("method"));
		if (method == 0) {
			this.addArticleType(request, response);
		}
		if (method == 1) {
			this.deleteArticleType(request, response);
		}
		if (method == 2) {
			this.addArticle(request, response);
		}
		if (method == 3) {
			this.deleteArticle(request, response);
		}
		if (method == 4) {
			this.updateArticle(request, response);
		}
		if (method == 5) {
			this.headAddNumberArticle(request, response);
		}
		if (method == 6) {
			this.deleteRestore(request, response);
		}
		if (method == 7) {
			this.HeadAddRestore(request, response);
		}
	}

	public void HeadAddRestore(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		restoreDao = new RestoreDao();
		RestoreForm restoreForm = new RestoreForm();
		restoreForm.setArticleId(Integer.valueOf(request.getParameter("articleId")));
		restoreForm.setReAccount(request.getParameter("accountId"));
		restoreForm.setReTitle(Chinese.toChinese(request.getParameter("reTitle")));
		restoreForm.setReContent(Chinese.toChinese(request.getParameter("reContent")));
		if (restoreDao.operationRestore("添加", restoreForm)) {
			out
					.print("<script language=javascript>alert('添加回复信息成功,请重新查询!');window.location.href='head_ArticleForm.jsp?id="+request.getParameter("articleId")+"';</script>");
		} else {
			out
					.print("<script language=javascript>alert('添加回复信息失败!');history.go(-1);</script>");
		}

	}

	public void deleteRestore(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		restoreDao = new RestoreDao();
		RestoreForm restoreForm = new RestoreForm();
		restoreForm.setId(Integer.valueOf(request.getParameter("id")));
	
		if (this.restoreDao.operationRestore("删除", restoreForm)) {
			out
					.print("<script language=javascript>alert('删除回复成功,请重新查询!');window.location.href='back_RestoreSelect.jsp?id="
							+ request.getParameter("idd") + "';</script>");
		} else {
			out
					.print("<script language=javascript>alert('删除回复失败!');history.go(-1);</script>");
		}

	}

	// 增加访问次数
	public void headAddNumberArticle(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ArticleForm articleForm = new ArticleForm();
		articleDao = new ArticleDao();
		articleForm.setId(Integer.valueOf(request.getParameter("id")));
		articleDao.operationArticle("增加", articleForm);
		request.setAttribute("form", articleDao.queryArticleForm(Integer
				.valueOf(request.getParameter("id"))));
		RequestDispatcher requestDispatcher = request
				.getRequestDispatcher("head_ArticleForm.jsp");
		requestDispatcher.forward(request, response);
	}

	public void updateArticle(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		ArticleForm articleForm = new ArticleForm();
		articleForm.setId(Integer.valueOf(request.getParameter("id")));
		articleForm.setTypeId(Integer.valueOf(request.getParameter("typeId")));
		articleForm.setTitle(Chinese.toChinese(request.getParameter("title")));
		articleForm.setContent(Chinese.toChinese(request
				.getParameter("content")));
		articleDao = new ArticleDao();
		if (articleDao.operationArticle("修改", articleForm)) {
			out
					.print("<script language=javascript>alert('修改文章成功,请重新查询!');window.location.href='back_ArticleSelect.jsp';</script>");
		} else {
			out
					.print("<script language=javascript>alert('修改文章失败!');history.go(-1);</script>");
		}
	}

	// 后台删除文章
	public void deleteArticle(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		ArticleForm articleForm = new ArticleForm();
		articleForm.setId(Integer.valueOf(request.getParameter("id")));
		articleDao = new ArticleDao();
		if (articleDao.operationArticle("删除", articleForm)) {
			out
					.print("<script language=javascript>alert('删除文章成功,请重新查询!');window.location.href='back_ArticleSelect.jsp';</script>");
		} else {
			out
					.print("<script language=javascript>alert('删除文章失败!');history.go(-1);</script>");
		}
	}

	// 后台添加文章
	public void addArticle(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		ArticleForm articleForm = new ArticleForm();
		articleForm.setTypeId(Integer.valueOf(request.getParameter("typeId")));
		articleForm.setTitle(Chinese.toChinese(request.getParameter("title")));
		articleForm.setNumber(Integer.valueOf(request.getParameter("number")));
		articleForm.setContent(Chinese.toChinese(request
				.getParameter("content")));
		articleForm
				.setPhTime(Chinese.toChinese(request.getParameter("phTime")));
		articleDao = new ArticleDao();
		String result = "文章添加失败!";
		if (articleDao.operationArticle("添加", articleForm)) {
			result = "文章添加成功!";
		}
		request.setAttribute("result", result);
		RequestDispatcher requestDispatcher = request
				.getRequestDispatcher("back_ArticleAdd.jsp");
		requestDispatcher.forward(request, response);
	}

	// 后台删除文章类别
	public void deleteArticleType(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		ArticleTypeForm ArticleTypeForm = new ArticleTypeForm();
		ArticleTypeForm.setId(Integer.valueOf(request.getParameter("id")));
		articleTypeDao = new ArticleTypeDao();
		if (articleTypeDao.operationArticleType("删除", ArticleTypeForm)) {
			out
					.print("<script language=javascript>alert('删除文章类别成功,请重新查询!');window.location.href='back_ArticleTypeSelect.jsp';</script>");
		} else {
			out
					.print("<script language=javascript>alert('您需要将类别所在的文章删除,才可删除此类别!');history.go(-1);</script>");
		}

	}

	// 后台添加文章类别
	public void addArticleType(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		PrintWriter out = response.getWriter();
		ArticleTypeForm ArticleTypeForm = new ArticleTypeForm();
		ArticleTypeForm.setTypeName(Chinese.toChinese(request
				.getParameter("typeName")));
		ArticleTypeForm.setDescription(Chinese.toChinese(request
				.getParameter("description")));
		articleTypeDao = new ArticleTypeDao();
		if (articleTypeDao.operationArticleType("添加", ArticleTypeForm)) {
			out
					.print("<script language=javascript>alert('添加文章类别成功,请重新查询!');window.location.href='back_ArticleTypeSelect.jsp';</script>");
		} else {
			out
					.print("<script language=javascript>alert('添加文章类别失败!');history.go(-1);</script>");
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程千纸鹤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值