コード例 #1
0
  /* ------------------------------------------------------------ */
  public ServletOutputStream getOutputStream() {
    if (_outputState == DISABLED) return __nullServletOut;

    if (_outputState != NO_OUT && _outputState != OUTPUTSTREAM_OUT)
      throw new IllegalStateException();

    if (_writer != null) {
      _writer.flush();
      _writer.disable();
      _writer = null;
    }

    if (_out == null) _out = new ServletOut(_servletHttpRequest.getHttpRequest().getOutputStream());
    _outputState = OUTPUTSTREAM_OUT;
    return _out;
  }
コード例 #2
0
  /* ------------------------------------------------------------ */
  public void sendRedirect(String url) throws IOException {
    if (url == null) throw new IllegalArgumentException();

    if (!URI.hasScheme(url)) {
      StringBuffer buf = _servletHttpRequest.getHttpRequest().getRootURL();
      if (url.startsWith("/")) buf.append(URI.canonicalPath(url));
      else {
        String path = _servletHttpRequest.getRequestURI();
        String parent = (path.endsWith("/")) ? path : URI.parentPath(path);
        url = URI.canonicalPath(URI.addPaths(parent, url));
        if (!url.startsWith("/")) buf.append('/');
        buf.append(url);
      }

      url = buf.toString();
    }

    resetBuffer();

    _httpResponse.setField(HttpFields.__Location, url);
    _httpResponse.setStatus(HttpResponse.__302_Moved_Temporarily);
    complete();
  }