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

📄 operationtopicaction.java

📁 struts+hibernate BBS mysql数据库 功能基本齐全
💻 JAVA
字号:
package com.elan.forum.actions.topic;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.elan.forum.model.ForumTopic;
import com.elan.forum.model.Forumtopicreply;
import com.elan.forum.elf.El;
import com.elan.forum.util.Constents;

public class OperationTopicAction extends DispatchAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return super.execute(mapping, form, request, response);
	}

	public ActionForward getAllTopic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<ForumTopic> alist = null;
		alist = El.getEl().getForumAdminMgr().getAllTopic();
		if (alist == null || 0 == alist.size()) {
			ActionMessages msgs = new ActionMessages();
			msgs.add("msgs", new ActionMessage("no.more.topic"));
			request.setAttribute("msgs", msgs);
			System.out.println("this is null list");
		}
		request.setAttribute("topicList", alist);
		System.out.println(alist);
		return mapping.findForward("topicList");
	}

	public ActionForward getAllTopicById(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = -1;
		ActionErrors errors = null;
		try {
			id = Integer.valueOf(request.getParameter("id"));
		} catch (Exception e) {
			errors = new ActionErrors();
			errors.add("gettopicbyiderr", new ActionMessage("param.err"));
			saveErrors(request, errors);
			System.out.println(id);
			return (mapping.findForward("userError"));
		}

		request
				.setAttribute("topic", El.getEl().getTopicMgr()
						.getTopicById(id));
		return mapping.findForward("showAritcle");
	}

	public ActionForward getAllTopicType(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setAttribute("topicType", El.getEl().getTopicMgr()
				.getAllTopicType());
		return mapping.findForward("getTopicTypeSuccess");
	}

	// 显示piece字模块的文章
	public ActionForward showPiece(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		Integer pieceId = Integer.valueOf(request.getParameter("pieceId"));
		List<ForumTopic> list = El.getEl().getTopicMgr().findPiece(pieceId);
		if (list != null && list.size() > 0) {
			
			StringBuffer strPath = new StringBuffer();
			strPath
					.append("<a href=\"")
					.append(request.getContextPath())
					.append(
							"/forum/operationTopic.do?method=showPiece&pieceId=")
					.append(pieceId).append("\">").append(
							((ForumTopic) list.get(0)).getPiece().getName())
					.append("</a>");
			request.setAttribute("currentPath", strPath.toString());
			request.setAttribute("pieceTopic", list);
		} else {
			// 找不到任何文章的piece
			// strPath += "找不到任何文章";
			// System.out.println(strPath);
			ActionMessages messages = new ActionMessages();
			messages.add("", new ActionMessage("piece.no.topic"));
			saveMessages(request, messages);
		}

		return mapping.findForward("showPiece");
	}

	/*
	 * 显示帖子
	 */
	public ActionForward showPieceTopic(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Integer topicId = Integer.valueOf(request.getParameter("topicId"));
		ForumTopic fa = El.getEl().getTopicMgr().findPieceTopic(topicId);
		if (fa == null) {
			ActionErrors errors = new ActionErrors();
			errors.add("", new ActionError("topic.no.find"));
			saveErrors(request, errors);
			return mapping.findForward("topicNotFind");
		}
		StringBuffer strPath = new StringBuffer();
		strPath
				.append("<a href=\"")
				.append(request.getContextPath())
				.append("/forum/operationTopic.do?method=showPiece&pieceId=")
				.append(fa.getPiece().getId())
				.append("\">")
				.append(fa.getPiece().getName())
				.append(">></a>")
				.append("<a href=\"")
				.append(request.getContextPath())
				.append("/forum/operationTopic.do?method=showPieceTopic&topicId=")
				.append(topicId).append("\">")
				.append(fa.getTitle())
				.append(
						"</a>");
		request.setAttribute("currentPath", strPath.toString());
		List<Forumtopicreply> falist = El.getEl().getTopicMgr().findTopicReply(
				topicId);
		request.setAttribute("reply", falist);
		request.setAttribute("pieceTopic", fa);
		request.setAttribute("pieceId", fa.getPiece().getId());
		System.out.println(fa.getPiece().getId());
		return mapping.findForward("showPieceTopic");
	}

	/*
	 * 获取回复
	 */
	public ActionForward findTopicReply(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return null;
	}

	/*
	 * 
	 */
	//
	@SuppressWarnings("unused")
	private String creareLinkUrl(HttpServletRequest request, String Url,
			String parameter) {
		StringBuffer sb = new StringBuffer(Constents.PATH_FORUM);
		sb.append("<a href=\"").append(request.getContextPath()).append(Url)
				.append(Url).append(parameter).append("\">").append("</a>");
		return sb.toString();
	}
}

⌨️ 快捷键说明

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