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

📄 deliveryservlet.java

📁 一个javaweb开的小例子
💻 JAVA
字号:
package cn.com.pkusoft.web;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.com.pkusoft.action.BaseAction;
import cn.com.pkusoft.comm.Logger;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: pku-soft</p>
 * @author weiming
 * @version 1.0
 */

public class DeliveryServlet
    extends HttpServlet
{
    private static final String CONTENT_TYPE = "text/html; charset=GB2312";
    private static final String ACTION_CLASS_BASE = "cn.com.pkusoft.action.";

    private static String ACTION_MAP = "actionMap";

    //Action类的目录位置
    private static String ACTION_DIR = "DIR";

    //Action类的名称
    private static String NEXT_ACTION = "ACTION";

    //Initialize global variables
    public void init() throws ServletException
    {
    }

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

    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        HttpSession session = request.getSession();
        Map actionMap = (Map) session.getAttribute(ACTION_MAP);
        if (actionMap == null)
        {
            actionMap = new HashMap();
            session.setAttribute(ACTION_MAP, actionMap);
        }

        ServletContext context = this.getServletContext();
        String dir = request.getParameter(ACTION_DIR);

        String nextAction = request.getParameter(NEXT_ACTION);

        if (dir == null || dir.equals(""))
        {
            Logger.logDebug("画面迁移失败(未指定迁移目录)!");
        }

        if (nextAction == null || nextAction.equals(""))
        {
            Logger.logDebug("画面迁移失败(未指定迁移页面)!");
        }

        BaseAction commonAction = (BaseAction) actionMap.get(NEXT_ACTION);

        if (commonAction == null)
        {
            String className = ACTION_CLASS_BASE;

            //**********指定ACTION的类名
            className = className + dir + "." + nextAction + "Action";
			System.out.println("呵呵---------------------" + className);

            Logger.logDebug("---the Action className is :" + className);

            try
            {
                Class actionClass = Class.forName(className);

                commonAction = (BaseAction) actionClass.newInstance();
            }
            catch (Exception ex)
            {
                Logger.logDebug("画面迁移失败(载入页面失败)!");
            }

            commonAction.setRequest(request);
            commonAction.setResponse(response);
            commonAction.setServletContext(context);

            commonAction.init();

            commonAction.execute();
        }

    }

    //Clean up resources
    public void destroy()
    {
    }
}

⌨️ 快捷键说明

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