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

📄 editthreadaction.java

📁 一个功能较为完善的论坛
💻 JAVA
字号:
/*
 * XP Forum
 *	
 * Copyright (c) 2002-2003 RedSoft Group.  All rights reserved.
 *
 */
package org.redsoft.forum.web;

import org.apache.struts.action.Action;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.dao.ThreadDAO;
import org.redsoft.forum.dao.PersistentThread;
import org.redsoft.forum.ForumConstants;
import java.io.IOException;
import java.sql.SQLException;
import org.redsoft.forum.exception.ThreadNotFoundException;

/**
 * Edit a thread
 *
 * @@author <a href="mailto:chjxm@msn.com">cinc</a>
 *
 * @@version $Id: EditThreadAction.java,v 1.1.1.1 2003/07/08 08:25:17 cinc Exp $
 */
public final class EditThreadAction extends Action {
    public ActionForward perform(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
	throws IOException, ServletException {
	   	HttpSession session = request.getSession();
	    final ActionErrors errors = new ActionErrors();
    	final String threadID = ((EditThreadForm) form).getThreadID();
		final String subject = ((EditThreadForm) form).getSubject();
		final String content = ((EditThreadForm) form).getContent();
	    final String notifyString = ((EditThreadForm) form).getNotify();
	    
	    String category = "1";
	    String parentID = "-1";

	    boolean notify = false;
	    if( notifyString != null &&  notifyString.equals("Y") ){
			notify = true;
		}
	    try{
    	    final ThreadDAO dao = DAOFactory.getInstance().getThreadDAO();
    	    final PersistentThread thread = dao.findByUID( Long.parseLong( threadID ) );
    	    // set category and parentID
    	    category = "" + thread.getCategory();
    	    thread.setTitle(subject);
    	    thread.setContent(content);
    	    thread.setNotify(notify);
    	    dao.updateThread(thread);
	    }catch( final SQLException sqlException ){
    	    sqlException.printStackTrace();
        	return (mapping.findForward("error"));
	    }catch( final ThreadNotFoundException threadNotFound ){
    	    threadNotFound.printStackTrace();
        	return (mapping.findForward("error"));
	    }
    // Report any errors we have discovered back to the original form
	if (!errors.empty()) {
	    saveErrors(request, errors);
	    return (new ActionForward(mapping.getInput()));
	}

    // Remove the obsolete form bean
	if (mapping.getAttribute() != null) {
            if ("request".equals(mapping.getScope()))
                request.removeAttribute(mapping.getAttribute());
            else
                session.removeAttribute(mapping.getAttribute());
        }

	// Forward control to the specified success URI
	request.setAttribute( ForumConstants.FORUM_ID_PARAM, category );
	return (mapping.findForward("success"));
	}
}

⌨️ 快捷键说明

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