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

📄 forumadminservlet.java

📁 java servlet著名论坛源代码
💻 JAVA
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumAdminServlet.java,v 1.2 2004/01/18 19:13:10 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.2 $
 * $Date: 2004/01/18 19:13:10 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2004 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package com.mvnforum.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mvnforum.MVNForumInfo;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.filter.IPFilter;
import net.myvietnam.mvncore.filter.UserAgentFilter;
import net.myvietnam.mvncore.util.ParamUtil;

public class ForumAdminServlet extends HttpServlet {

    private static Log log = LogFactory.getLog(ForumAdminServlet.class);

    private AdminModuleProcessor adminModuleProcessor  = null;
    private static int count = 0;

    /**Initialize global variables*/
    public void init() throws ServletException {
        adminModuleProcessor  = new AdminModuleProcessor(this);
        log.info("<<---- ForumAdminServlet has been inited.  Detailed info: " + MVNForumInfo.getProductVersion() + " (Build: " + MVNForumInfo.getProductReleaseDate() + ") ---->>");
    }

    /**Process the HTTP Get request*/
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        process(request, response);
    }

    /**Process the HTTP Post request*/
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        process(request, response);
    }

    public void process(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        long startTime = 0;
        if (log.isDebugEnabled()) {
            startTime = System.currentTimeMillis();
        }
        count++;
        try {
            request.setCharacterEncoding("utf-8");
            String requestURI = request.getPathInfo();
            String responseURI = null;

            if (IPFilter.filter(request) == false) {
                getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
                return;
            }
            if (UserAgentFilter.filter(request) == false) {
                getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
                return;
            }

            // this method should not throw Exception (it must catch all Exceptions)
            responseURI = adminModuleProcessor.process(request, response);
            //this IF ensures we don't try to redirect if already committed output
            if ( (null!=responseURI) && (!response.isCommitted()) ) {
               if (responseURI.endsWith(".jsp")) {
                  request.getRequestDispatcher(responseURI).forward(request, response);
               } else {
                  response.sendRedirect(ParamUtil.getContextPath() + responseURI);
               }
            }
        } catch (Exception e) {
            // so it should never go here
            log.error("Error assertion", e);
        } finally {
            if (log.isDebugEnabled()) {
                long processTime = System.currentTimeMillis() - startTime;
                log.debug("ForumAdminServlet processed " + count + " times. Took " + processTime + " miliseconds.\n");
            }
        }
    }// process

    /**
     * Clean up resources
     */
    public void destroy() {
        // This code will release all connections currently pooled.
        // The next call to #getConnection will recreate the pool.
        DBUtils.closeAllConnections();

        log.info("<<---- ForumAdminServlet has been destroyed. ---->>");
    }
}

⌨️ 快捷键说明

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