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

📄 postlinkaction.java

📁 如题ServletJSP.rar 为网络收集的JSP网站源文件
💻 JAVA
字号:
/*
 * XP Forum
 *
 * Copyright (c) 2002-2003 RedSoft Group.  All rights reserved.
 *
 */
package org.redsoft.forum.web;

import org.apache.struts.action.*;
import org.apache.struts.util.RequestUtils;
import org.redsoft.forum.exception.ThreadNotFoundException;
import org.redsoft.forum.ForumConstants;
import org.redsoft.forum.util.ForumUtils;
import org.redsoft.forum.dao.ThreadDAO;
import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.dao.PersistentThread;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.security.auth.Subject;
import java.io.IOException;
import java.sql.SQLException;
import org.redsoft.forum.dao.ForumDAO;


/**
 * A actino that wraps the link to post.jsp
 *
 * @author Charles Huang
 *
 * @version 1.0
 */
public class PostLinkAction extends Action {

    public ActionForward perform(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws IOException, ServletException {

		ActionErrors errors = new ActionErrors();

		final String forumID = request.getParameter(ForumConstants.FORUM_ID_PARAM);
		if(forumID == null || forumID.equals("")) {
			errors.add(ActionErrors.GLOBAL_ERROR,
		                           new ActionError("error.forumID.invalid"));
		}else{
			int forum = Integer.parseInt( forumID );
			ForumDAO forumDAO = DAOFactory.getInstance().getForumDAO();
			Forum[] forums = forumDAO.getForumCategory();

			if( forum > forums.length ){
				errors.add(ActionErrors.GLOBAL_ERROR,
		                           new ActionError("error.forumID.invalid"));
			}
		}

		// If this is a reply
		final String parentId = request.getParameter( "Id" );
		if( parentId != null && parentId.length() > 0 ){
			try{
				final ThreadDAO dao = DAOFactory.getInstance().getThreadDAO();
				final PersistentThread thread = dao.findByUID( Long.parseLong( parentId ) );

				// Return a immutable thread object back to jsp instead of a mutable PersistentThread object
				request.setAttribute( ForumConstants.MY_THREAD_PARAM,
									  new Thread( thread.getTitle(),
	               								  thread.getContent(),
        	       								  thread.getAuthor(),
	    	       								  thread.getTimeStamp(),
                   								  thread.getCategory() ) );
			}catch( final SQLException sqlException ){
				sqlException.printStackTrace();
				return (mapping.findForward("error"));
			}catch( final ThreadNotFoundException threadNotFoundException ){
				threadNotFoundException.printStackTrace();
				return (mapping.findForward("error"));
			}
		}


		// Report any errors we have discovered back to the original form
		if (!errors.empty()) {
				saveErrors(request, errors);
		}

        return (mapping.findForward("success"));
    }
}//EOC

⌨️ 快捷键说明

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