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

📄 forumuserservlet.java

📁 java servlet著名论坛源代码
💻 JAVA
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ForumUserServlet.java,v 1.5 2004/03/21 13:25:14 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.5 $
 * $Date: 2004/03/21 13:25:14 $
 *
 * ====================================================================
 *
 * 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.user;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mvnforum.*;
import com.mvnforum.auth.OnlineUser;
import com.mvnforum.auth.OnlineUserManager;
import com.mvnforum.db.WatchBean;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.filter.IPFilter;
import net.myvietnam.mvncore.filter.UserAgentFilter;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.TimerUtil;

public class ForumUserServlet extends HttpServlet {

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

    private UserModuleProcessor userModuleProcessor  = null;
    private static int count = 0;

    /**Initialize global variables*/
    public void init() throws ServletException {
        /*
        if (MVNForumConfig.isShouldRun() == false) {
            throw new ServletException("Cannot init system. Reason = " + MVNForumConfig.getReason());
        }*/

        userModuleProcessor  = new UserModuleProcessor(this);

        // Check if the servlet is in specs Servlet 2.3 or later
        if (MVNForumConfig.isShouldRun()) {
            ServletContext context = getServletContext();
            int majorVersion = context.getMajorVersion();
            int mimorVersion = context.getMinorVersion();
            if ((majorVersion < 2) ||
                ((majorVersion == 2) && (mimorVersion < 3))) {
                MVNForumConfig.setShouldRun(false, "mvnForum requires Servlet 2.3 or later. Please upgrade your Servlet Container.");
            }
        }

        // schedule the WatchTask
        if (MVNForumConfig.getEnableWatch()) {
            if (MVNForumConfig.isShouldRun()) {
                log.info("Schedule the WatchTask.");
                if (MVNForumConfig.getDefaultWatchOption() == WatchBean.WATCH_OPTION_LIVE) {
                    // The default watch is LIVE, so the timer is called more often (5 minutes)
                    WatchTask.getInstance().schedule(DateUtil.MINUTE, DateUtil.MINUTE * 5);
                } else {
                    // Other options, we only check the watch hourly
                    WatchTask.getInstance().schedule(DateUtil.MINUTE, DateUtil.HOUR);
                }
            }
        } else {
            log.info("Watch is disabled. Do not schedule the WatchTask.");
        }

        log.info("<<---- ForumUserServlet 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 {

        if (MVNForumConfig.isShouldRun() == false) {
            String error = "Cannot init system. Reason : " + MVNForumConfig.getReason();
            request.setAttribute("fatal_error_message", error);
            getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/fatalerror.jsp").forward(request, response);
            return;
        }

        long startTime = 0;
        if (log.isDebugEnabled()) {
            startTime = System.currentTimeMillis();
        }
        count++;
        try {
            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;
            }

            //request.setCharacterEncoding("utf-8");

            String responseURI = null;
            responseURI = ManagerFactory.getRequestProcessor().preLogin(request, response);

            // This will make sure that the user information is put in
            // the request.
            OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
            OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);

            if (null == responseURI) {
                responseURI = ManagerFactory.getRequestProcessor().preProcess(request, response);
            }

            if (null == responseURI) {
                // this method should not throw Exception (it must catch all Exceptions)
                responseURI = userModuleProcessor.process(request, response);
            }

            responseURI = ManagerFactory.getRequestProcessor().postProcess(request, response, responseURI);

            if (null != responseURI && !response.isCommitted()) {
                if (responseURI.endsWith(".jsp")) {
                    request.getRequestDispatcher(responseURI).forward(request, response);
                } else {
                    response.sendRedirect(request.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("ForumUserServlet 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();

        //finally, cancel the TimerUtil
        TimerUtil.getInstance().cancel();
        log.info("<<---- ForumUserServlet has been destroyed. ---->>");
    }
}

⌨️ 快捷键说明

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