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


Java Response.setHeader方法代碼示例

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


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

示例1: setAuthenticateHeader

import org.apache.catalina.connector.Response; //導入方法依賴的package包/類
/**
 * Generates the WWW-Authenticate header.
 * <p>
 * The header MUST follow this template :
 * <pre>
 *      WWW-Authenticate    = "WWW-Authenticate" ":" "Digest"
 *                            digest-challenge
 *
 *      digest-challenge    = 1#( realm | [ domain ] | nOnce |
 *                  [ digest-opaque ] |[ stale ] | [ algorithm ] )
 *
 *      realm               = "realm" "=" realm-value
 *      realm-value         = quoted-string
 *      domain              = "domain" "=" <"> 1#URI <">
 *      nonce               = "nonce" "=" nonce-value
 *      nonce-value         = quoted-string
 *      opaque              = "opaque" "=" quoted-string
 *      stale               = "stale" "=" ( "true" | "false" )
 *      algorithm           = "algorithm" "=" ( "MD5" | token )
 * </pre>
 *
 * @param request HTTP Servlet request
 * @param response HTTP Servlet response
 * @param config    Login configuration describing how authentication
 *              should be performed
 * @param nOnce nonce token
 */
protected void setAuthenticateHeader(Request request,
                                     Response response,
                                     LoginConfig config,
                                     String nOnce) {

    // Get the realm name
    String realmName = config.getRealmName();
    if (realmName == null)
        realmName = request.getServerName() + ":"
            + request.getServerPort();

    byte[] buffer = null;
    synchronized (md5Helper) {
        buffer = md5Helper.digest(nOnce.getBytes());
    }

    String authenticateHeader = "Digest realm=\"" + realmName + "\", "
        +  "qop=\"auth\", nonce=\"" + nOnce + "\", " + "opaque=\""
        + md5Encoder.encode(buffer) + "\"";
    response.setHeader("WWW-Authenticate", authenticateHeader);

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:50,代碼來源:DigestAuthenticator.java


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