if (session != null || !isErrorHandling) {
if (session != null && !isErrorHandling) {
    public final synchronized void doGet(HttpServletRequest req,                                         HttpServletResponse response) {        SessionManager.setSession(session);        session.setServletRequest(req);        session.setServletResponse(response);        session.fireRequestEvent(SRequestEvent.REQUEST_START);        // in case, the previous thread did not clean up.        SForm.clearArmedComponents();        Device outputDevice = null;        ReloadManager reloadManager = session.getReloadManager();                boolean isErrorHandling = false;                try {            /*             * The tomcat 3.x has a bug, in that it does not encode the URL             * sometimes. It does so, when there is a cookie, containing some             * tomcat sessionid but that is invalid (because, for instance,             * we restarted the tomcat in-between).              * [I can't think of this being the correct behaviour, so I assume             *  it is a bug. ]             *             * So we have to workaround this here: if we actually got the             * session id from a cookie, but it is not valid, we don't do             * the encodeURL() here: we just leave the requestURL as it is             * in the properties .. and this is url-encoded, since             * we had set it up in the very beginning of this session              * with URL-encoding on  (see WingServlet::newSession()).             *             * Vice versa: if the requestedSessionId is valid, then we can             * do the encoding (which then does URL-encoding or not, depending             * whether the servlet engine detected a cookie).             * (hen)             */            RequestURL requestURL = null;            if (req.isRequestedSessionIdValid()) {                requestURL = new RequestURL("", getSessionEncoding(response));                // this will fire an event, if the encoding has changed ..                ((PropertyService) session).setProperty("request.url",                        requestURL);            }            if (log.isDebugEnabled()) {                log.debug("request URL: " + requestURL);                log.debug("HTTP header:");                for (Enumeration en = req.getHeaderNames(); en.hasMoreElements();) {                    String header = (String) en.nextElement();                    log.debug("   " + header + ": " + req.getHeader(header));                }            }            handleLocale(req);            Enumeration en = req.getParameterNames();            Cookie[] cookies = req.getCookies();            // are there parameters/low level events to dispatch            if (en.hasMoreElements()) {                // only fire DISPATCH_START if we have parameters to dispatch                session.fireRequestEvent(SRequestEvent.DISPATCH_START);                if (cookies != null) {                    //dispatch cookies                    for (int i = 0; i < cookies.length; i++) {                        Cookie cookie = cookies[i];                        String paramName = (String) cookie.getName();                        String value = cookie.getValue();                            if (log.isDebugEnabled())                            log.debug("dispatching cookie " + paramName + " = " + value);                            session.getDispatcher().dispatch(paramName, new String[] { value });                    }                }                while (en.hasMoreElements()) {                    String paramName = (String) en.nextElement();                    String[] value = req.getParameterValues(paramName);                    if (log.isDebugEnabled())                        log.debug("dispatching " + paramName + " = " + Arrays.asList(value));                    session.getDispatcher().dispatch(paramName, value);                }                SForm.fireEvents();                            // only fire DISPATCH DONE if we have parameters to dispatch                session.fireRequestEvent(SRequestEvent.DISPATCH_DONE);            }            session.fireRequestEvent(SRequestEvent.PROCESS_REQUEST);                                    // if the user chose to exit the session as a reaction on an            // event, we got an URL to redirect after the session.            /*             * where is the right place?             * The right place is              *    - _after_ we processed the events              *        (e.g. the 'Pressed Exit-Button'-event or gave             *         the user the chance to exit this session in the custom             *         processRequest())             *    - but _before_ the rendering of the page,             *      because otherwise an redirect won't work, since we must             *      not have sent anything to the output stream).             */            if (session.getExitAddress() != null) {                try {                    session.firePrepareExit();                    String redirectAddress;                    if (session.getExitAddress().length() > 0) {                        // redirect to user requested URL.                        redirectAddress = session.getExitAddress();                    } else {                        // redirect to a fresh session.                        redirectAddress = req.getRequestURL().toString();                    }                    req.getSession().invalidate(); // calls destroy implicitly                    response.sendRedirect(redirectAddress);                    return;                } catch (ExitVetoException ex) {                    session.exit(null);                } // end of try-catch            }            if (session.getRedirectAddress() != null) {                // redirect to user requested URL.                response.sendRedirect(session.getRedirectAddress());                session.setRedirectAddress(null);                return;            }                        // invalidate frames and resources            reloadManager.invalidateResources();            reloadManager.notifyCGs();            // deliver resource. The            // externalizer is able to handle static and dynamic resources            ExternalizeManager extManager = getSession().getExternalizeManager();            String pathInfo = req.getPathInfo().substring(1);            log.debug("pathInfo: " + pathInfo);            /*             * if we have no path info, or the special '_' path info             * (that should be explained somewhere, Holger), then we             * deliver the toplevel Frame of this application.             */            String externalizeIdentifier = null;            if (pathInfo == null                    || pathInfo.length() == 0                    || "_".equals(pathInfo)                    || firstRequest) {                log.debug("delivering default frame");                if (session.getFrames().size() == 0)                    throw new ServletException("no frame visible");                                // get the first frame from the set and walk up the hierarchy.                // this should work in most cases. if there are more than one                // toplevel frames, the developer has to care about the resource                // ids anyway ..                SFrame defaultFrame = (SFrame) session.getFrames().iterator().next();                while (defaultFrame.getParent() != null)                    defaultFrame = (SFrame) defaultFrame.getParent();                                 Resource resource = defaultFrame.getDynamicResource(DynamicCodeResource.class);                externalizeIdentifier = resource.getId();                firstRequest = false;            } else {                externalizeIdentifier = pathInfo;            }                        // externalized this resource.            ExternalizedResource extInfo = extManager                    .getExternalizedResource(externalizeIdentifier);            if (extInfo != null) {                outputDevice = DeviceFactory.createDevice(extInfo);                //outputDevice = createOutputDevice(req, response, extInfo);                session.fireRequestEvent(SRequestEvent.DELIVER_START, extInfo);                extManager.deliver(extInfo, response, outputDevice);                session.fireRequestEvent(SRequestEvent.DELIVER_DONE, extInfo);            } else {                handleUnknownResourceRequested(req, response);            }        } catch (Throwable e) {            /*             * error handling...implement it in SFrame             */            SFrame defaultFrame = (SFrame) session.getFrames().iterator().next();            while (defaultFrame.getParent() != null)                defaultFrame = (SFrame) defaultFrame.getParent();            if (defaultFrame != null && defaultFrame.handleError(e)) {                doGet(req, response);                isErrorHandling = true;                return;            } else {                log.fatal("exception: ", e);                handleException(response, e);            }                    } finally {            if (session != null || !isErrorHandling) {                session.fireRequestEvent(SRequestEvent.REQUEST_END);            }            if (outputDevice != null) {                try {                    outputDevice.close();                } catch (Exception e) {                }            }            /*             * the session might be null due to destroy().             */            if (session != null || !isErrorHandling) {                reloadManager.clear();                session.setServletRequest(null);                session.setServletResponse(null);            }            // make sure that the session association to the thread is removed            // from the SessionManager            SessionManager.removeSession();            SForm.clearArmedComponents();        }    }