示例#1
0
  /**
   * Internal method that allows a redirect to be sent with a status other than {@link
   * HttpServletResponse#SC_FOUND} (302). No attempt is made to validate the status code.
   */
  public void sendRedirect(String location, int status) throws IOException {
    if (isCommitted()) {
      throw new IllegalStateException(sm.getString("coyoteResponse.sendRedirect.ise"));
    }

    // Ignore any call from an included servlet
    if (included) {
      return;
    }

    // Clear any data content that has been buffered
    resetBuffer(true);

    // Generate a temporary redirect to the specified location
    try {
      String absolute = toAbsolute(location);
      setStatus(status);
      setHeader("Location", absolute);
      if (getContext().getSendRedirectBody()) {
        PrintWriter writer = getWriter();
        writer.print(
            sm.getString("coyoteResponse.sendRedirect.note", RequestUtil.filter(absolute)));
        flushBuffer();
      }
    } catch (IllegalArgumentException e) {
      setStatus(SC_NOT_FOUND);
    }

    // Cause the response to be finished (from the application perspective)
    setSuspended(true);
  }
  @Override
  public void flushBuffer() throws IOException {

    if (isFinished())
      //            throw new IllegalStateException
      //                (/*sm.getString("responseFacade.finished")*/);
      return;

    if (SecurityUtil.isPackageProtectionEnabled()) {
      try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction<Void>() {

              @Override
              public Void run() throws IOException {
                response.setAppCommitted(true);

                response.flushBuffer();
                return null;
              }
            });
      } catch (PrivilegedActionException e) {
        Exception ex = e.getException();
        if (ex instanceof IOException) {
          throw (IOException) ex;
        }
      }
    } else {
      response.setAppCommitted(true);

      response.flushBuffer();
    }
  }