event = new ServletRequestEvent(_context,request);
event = new ServletRequestEvent(_scontext,request);
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)            throws IOException, ServletException    {           boolean new_context=false;        Context old_context=null;        String old_context_path=null;        String old_servlet_path=null;        String old_path_info=null;        ClassLoader old_classloader=null;        Thread current_thread=null;                Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();        if( !isStarted() || _shutdown || (dispatch==REQUEST && base_request.isHandled()))            return;                old_context=base_request.getContext();                // Are we already in this context?        if (old_context!=_context)        {            new_context=true;                        // Check the vhosts            if (_vhosts!=null && _vhosts.length>0)            {                String vhost=request.getServerName();                boolean match=false;                                // TODO non-linear lookup                for (int i=0;!match && i<_vhosts.length;i++)                    match=_vhosts[i]!=null && _vhosts[i].equalsIgnoreCase(vhost);                if (!match)                    return;            }                        // Check the connector            if (_connectors!=null && _connectors.size()>0)            {                String connector=HttpConnection.getCurrentConnection().getConnector().getName();                if (connector==null || !_connectors.contains(connector))                    return;            }                        // Nope - so check the target.            if (dispatch==REQUEST)            {                if (target.equals(_contextPath))                {                    target=_contextPath;                    if (!target.endsWith("/"))                    {                        base_request.setHandled(true);                        if (request.getQueryString()!=null)                            response.sendRedirect(target+"/?"+request.getQueryString());                        else                             response.sendRedirect(target+"/");                        return;                    }                }                else if (target.startsWith(_contextPath) && (_contextPath.length()==1 || target.charAt(_contextPath.length())=='/'))                {                    if (_contextPath.length()>1)                        target=target.substring(_contextPath.length());                }                else                 {                    // Not for this context!                    return;                }            }        }                try        {            old_context_path=base_request.getContextPath();            old_servlet_path=base_request.getServletPath();            old_path_info=base_request.getPathInfo();                        // Update the paths            base_request.setContext(_context);            if (dispatch!=INCLUDE && target.startsWith("/"))            {                if (_contextPath.length()==1)                    base_request.setContextPath("");                else                    base_request.setContextPath(_contextPath);                base_request.setServletPath(null);                base_request.setPathInfo(target);            }            ServletRequestEvent event=null;            if (new_context)            {                // Set the classloader                if (_classLoader!=null)                {                    current_thread=Thread.currentThread();                    old_classloader=current_thread.getContextClassLoader();                    current_thread.setContextClassLoader(_classLoader);                }                                // Handle the REALLY SILLY request events!                if (_requestListeners!=null)                {                    event = new ServletRequestEvent(_context,request);                    for(int i=0;i<LazyList.size(_requestListeners);i++)                        ((ServletRequestListener)LazyList.get(_requestListeners,i)).requestInitialized(event);                }                for(int i=0;i<LazyList.size(_requestAttributeListeners);i++)                    base_request.addEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));            }                        // Handle the request            try            {                if (dispatch==REQUEST && isProtectedTarget(target))                    throw new HttpException(HttpServletResponse.SC_NOT_FOUND);                                Handler handler = getHandler();                if (handler!=null)                    handler.handle(target, request, response, dispatch);            }            catch(HttpException e)            {                Log.debug(e);                response.sendError(e.getStatus(), e.getReason());            }            finally            {                // Handle more REALLY SILLY request events!                if (new_context)                {                    for(int i=LazyList.size(_requestListeners);i-->0;)                        ((ServletRequestListener)LazyList.get(_requestListeners,i)).requestDestroyed(event);                                        for(int i=0;i<LazyList.size(_requestAttributeListeners);i++)                        base_request.removeEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));                }            }        }        finally        {            if (old_context!=_context)            {                // reset the classloader                if (_classLoader!=null)                {                    current_thread.setContextClassLoader(old_classloader);                }                                // reset the context and servlet path.                base_request.setContext(old_context);                base_request.setContextPath(old_context_path);                base_request.setServletPath(old_servlet_path);                base_request.setPathInfo(old_path_info);             }        }    }