Пример #1
0
  /**
   * Set the content type for this Response.
   *
   * @param type The new content type
   */
  @Override
  public void setContentType(String type) {

    if (isCommitted()) {
      return;
    }

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

    if (type == null) {
      coyoteResponse.setContentType(null);
      return;
    }

    String[] m = MEDIA_TYPE_CACHE.parse(type);
    if (m == null) {
      // Invalid - Assume no charset and just pass through whatever
      // the user provided.
      coyoteResponse.setContentTypeNoCharset(type);
      return;
    }

    coyoteResponse.setContentTypeNoCharset(m[0]);

    if (m[1] != null) {
      // Ignore charset if getWriter() has already been called
      if (!usingWriter) {
        coyoteResponse.setCharacterEncoding(m[1]);
        isCharacterEncodingSet = true;
      }
    }
  }