⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 articledo.java

📁 一个bbs论坛系统
💻 JAVA
字号:
package com.lovo.servlet;

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

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.lovo.factory.BOFactory;
import com.lovo.po.FilePO;
import com.lovo.po.LevelPO;
import com.lovo.po.PublishPO;
import com.lovo.po.ReplyPO;
import com.lovo.po.UserPO;
import com.lovo.util.Page;

public class ArticleDO extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		
		HttpSession session = request.getSession(true); //获得session作用域

		String publishIdStr = request.getParameter("publishId"); //从页面上获得主题帖的ID的字符串

		int publishId = Integer.parseInt(publishIdStr);

		PublishPO publish = 
			BOFactory.getPublishBOInstance().queryById(publishId); //通过ID查询到主题帖
		
		//通过主题帖的发表人的ID找到发表人
		UserPO publishMan = 
			BOFactory.getUserBOInstance().queryById(publish.getPublishMan().getId()); 
		
		//根据发表人的等级ID找到相应的等级对象
		LevelPO level =
			BOFactory.getLevelBOInstance().queryLevelById(publishMan.getLevel().getLevelNum());

		//对发表人的对象的等级填充
		publishMan.setLevel(level);

		//对主题帖的作者填充
		publish.setPublishMan(publishMan);

		//查询该用户共发表了多少帖子
		List<PublishPO> list = BOFactory.getPublishBOInstance()
				.queryPubByUserid(publishMan.getId());
		int publishNum = list.size();
		session.setAttribute("publish", publish);
		
		String currPageStr = request.getParameter("page");
		
		int currPage = 1;
		try {
			currPage = Integer.parseInt(currPageStr);
		} catch (NumberFormatException e) {
			currPage = 1;
		}
		
		if(currPage <= 0) {
			currPage = 1;
		}
		
		int maxRows = BOFactory.getReplyBoInstance().queryRepNumByPublish(publishId);
		
		Page replyPage = new Page();
		replyPage.setCurrPage(currPage);
		replyPage.setMaxRows(maxRows);
		
		int maxPages = maxRows % replyPage.getPageRows() == 0 ? maxRows / replyPage.getPageRows() : maxRows / replyPage.getPageRows() + 1;
		if(maxPages == 0) {
			maxPages = 1;
		}
		if(currPage >= maxPages) {
			if(maxPages != 0) {
				currPage = maxPages;
				replyPage.setCurrPage(currPage);
			}
		}
		
		//查询该主题贴的所有回帖
		List<ReplyPO> replyList = BOFactory.getReplyBoInstance().queryRepByPublish(publishId, replyPage);
		
		//对回帖的用户进行填充
		if (replyList != null) {
			for (int i = 0; i < replyList.size(); i++) {
				ReplyPO reply = replyList.get(i);
				UserPO replyMan = BOFactory.getUserBOInstance().queryById(reply.getReplyMan().getId());
				reply.setReplyMan(replyMan);
			}
		}
		
		try {
			List<FilePO> fileList = BOFactory.getFileBOInstance().queryFileByPublishId(publishId);
			session.setAttribute("fileList", fileList);
		} catch (SQLException e) {
			e.printStackTrace();
			response.sendRedirect("../web/error.jsp");
			return;
		}
		session.setAttribute("replyList", replyList); 
		session.setAttribute("replyPage", replyPage);
		session.setAttribute("currPage", currPage);
		response.sendRedirect("../web/jsp/article.jsp?publishNum=" + publishNum + "&maxPages=" + maxPages);

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -