當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletResponse.reset方法代碼示例

本文整理匯總了Java中javax.servlet.ServletResponse.reset方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletResponse.reset方法的具體用法?Java ServletResponse.reset怎麽用?Java ServletResponse.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.ServletResponse的用法示例。


在下文中一共展示了ServletResponse.reset方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilter

import javax.servlet.ServletResponse; //導入方法依賴的package包/類
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
		final FilterChain chain) throws IOException, ServletException {
	if (request instanceof HttpServletRequest) {
		final HttpServletRequest req = ((HttpServletRequest) request);
		final HttpServletResponse res = ((HttpServletResponse) response);
		final String header = req.getHeader(SimpleAuth.HTTP_HEADER);
		if (header != null) {
			final String[] sp = header.split(" ");
			// Authentication: torch TOKEN
			if (sp.length == 2) {
				final String scheme = sp[0], param = sp[1];
				if (SimpleAuth.SCHEME.equals(scheme)) {
					if (sa.verify(param)) {
						chain.doFilter(request, response);
						return;
					}
				}
			}
		}
		if (!res.isCommitted()) {
			final String err = "FORBIDDEN\r\n";
			res.reset();
			res.setStatus(HttpServletResponse.SC_FORBIDDEN);
			res.setContentLength(err.length());
			res.setContentType("text/plain");
			res.setCharacterEncoding("ISO-8859-1");
			res.setHeader("Pragma", "no-cache");
			res.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate");
			res.setHeader(getClass().getSimpleName(), "deny");
			res.getWriter().print(err);
			return;
		}
	}
	if (!response.isCommitted()) {
		response.reset();
	}
	throw new ServletException(new UnsupportedOperationException());
}
 
開發者ID:ggrandes,項目名稱:simpleauth,代碼行數:40,代碼來源:SimpleAuthFilter.java

示例2: handleFirstRequest

import javax.servlet.ServletResponse; //導入方法依賴的package包/類
public void handleFirstRequest(final HttpServerExchange exchange, final ServletChain servletChain, final ServletRequestContext servletRequestContext, final ServletRequest request, final ServletResponse response) throws Exception {

        ThreadSetupAction.Handle handle = setupAction.setup(exchange);
        try {
            servletRequestContext.setRunningInsideHandler(true);
            try {
                listeners.requestInitialized(request);
                next.handleRequest(exchange);
                //
                if(servletRequestContext.getErrorCode() > 0) {
                    servletRequestContext.getOriginalResponse().doErrorDispatch(servletRequestContext.getErrorCode(), servletRequestContext.getErrorMessage());
                }
            } catch (Throwable t) {

                //by default this will just log the exception
                boolean handled = exceptionHandler.handleThrowable(exchange, request, response, t);

                if(handled) {
                    exchange.endExchange();
                } else if (request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC) {
                    exchange.unDispatch();
                    servletRequestContext.getOriginalRequest().getAsyncContextInternal().handleError(t);
                } else {
                    if (!exchange.isResponseStarted()) {
                        response.reset();                       //reset the response
                        exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
                        exchange.getResponseHeaders().clear();
                        String location = servletContext.getDeployment().getErrorPages().getErrorLocation(t);
                        if (location == null) {
                            location = servletContext.getDeployment().getErrorPages().getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
                        }
                        if (location != null) {
                            RequestDispatcherImpl dispatcher = new RequestDispatcherImpl(location, servletContext);
                            try {
                                dispatcher.error(servletRequestContext, request, response, servletChain.getManagedServlet().getServletInfo().getName(), t);
                            } catch (Exception e) {
                                UndertowLogger.REQUEST_LOGGER.exceptionGeneratingErrorPage(e, location);
                            }
                        } else {
                            if (servletRequestContext.displayStackTraces()) {
                                ServletDebugPageHandler.handleRequest(exchange, servletRequestContext, t);
                            } else {
                                servletRequestContext.getOriginalResponse().doErrorDispatch(StatusCodes.INTERNAL_SERVER_ERROR, StatusCodes.INTERNAL_SERVER_ERROR_STRING);
                            }
                        }
                    }
                }

            } finally {
                servletRequestContext.setRunningInsideHandler(false);
                listeners.requestDestroyed(request);
            }
            //if it is not dispatched and is not a mock request
            if (!exchange.isDispatched() && !(exchange.getConnection() instanceof MockServerConnection)) {
                servletRequestContext.getOriginalResponse().responseDone();
                servletRequestContext.getOriginalRequest().clearAttributes();
            }
            if(!exchange.isDispatched()) {
                AsyncContextImpl ctx = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
                if(ctx != null) {
                    ctx.complete();
                }
            }
        } finally {
            handle.tearDown();
        }
    }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:68,代碼來源:ServletInitialHandler.java

示例3: forward

import javax.servlet.ServletResponse; //導入方法依賴的package包/類
public void forward( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
    response.reset();
    _servletMetaData.getServlet().service( DispatchedRequestWrapper.createForwardRequestWrapper( (HttpServletRequest) request, this ), response );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:5,代碼來源:RequestDispatcherImpl.java

示例4: invoke

import javax.servlet.ServletResponse; //導入方法依賴的package包/類
/**
 * Invoke the next Valve in the sequence. When the invoke returns, check 
 * the response state, and output an error report is necessary.
 *
 * @param request The servlet request to be processed
 * @param response The servlet response to be created
 * @param context The valve context used to invoke the next valve
 *  in the current processing pipeline
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void invoke(Request request, Response response,
                   ValveContext context)
    throws IOException, ServletException {

    // Perform the request
    context.invokeNext(request, response);

    ServletRequest sreq = (ServletRequest) request;
    Throwable throwable = 
        (Throwable) sreq.getAttribute(Globals.EXCEPTION_ATTR);

    ServletResponse sresp = (ServletResponse) response;
    if (sresp.isCommitted()) {
        return;
    }

    if (throwable != null) {

        // The response is an error
        response.setError();

        // Reset the response (if possible)
        try {
            sresp.reset();
        } catch (IllegalStateException e) {
            ;
        }

        ServletResponse sresponse = (ServletResponse) response;
        if (sresponse instanceof HttpServletResponse)
            ((HttpServletResponse) sresponse).sendError
                (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    }

    response.setSuspended(false);

    try {
        report(request, response, throwable);
    } catch (Throwable tt) {
        tt.printStackTrace();
    }

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:57,代碼來源:ErrorReportValve.java


注:本文中的javax.servlet.ServletResponse.reset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。