Example usage for javax.servlet.http HttpServletResponse setHeader

List of usage examples for javax.servlet.http HttpServletResponse setHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setHeader.

Prototype

public void setHeader(String name, String value);

Source Link

Document

Sets a response header with the given name and value.

Usage

From source file:com.adito.security.AbstractHTTPAuthenticationModule.java

/**
 * @param request/*from  w  w  w  .j a  va2 s  .c om*/
 * @param response
 * @param realm
 * @throws IOException
 */
public static void sendAuthorizationError(HttpServletRequest request, HttpServletResponse response,
        String realm) throws IOException {
    if (log.isInfoEnabled())
        log.info("Sending auth request for realm " + realm);
    response.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    request.getSession().setAttribute(Constants.AUTH_SENT, Boolean.TRUE);
}

From source file:controller.file.FileUploader.java

public static void fileDownloader(HttpServletRequest request, HttpServletResponse response) {
    PrintWriter out = null;// ww w  . j  av a  2s. com
    try {
        String filename = "foo.xml";
        String filepath = "/tmp/";
        out = response.getWriter();
        response.setContentType("APPLICATION/OCTET-STREAM");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);
        int i;
        while ((i = fileInputStream.read()) != -1) {
            out.write(i);
        }
        fileInputStream.close();
        out.close();
    } catch (IOException ex) {
        Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        out.close();
    }
}

From source file:com.gc.core.framework.utils.web.ServletUtils.java

/**
 * ?Header./*from  w  w  w  . j a va2s. c o m*/
 */
public static void setDisableCacheHeader(HttpServletResponse response) {
    //Http 1.0 header
    response.setDateHeader("Expires", 1L);
    response.addHeader("Pragma", "no-cache");
    //Http 1.1 header
    response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
}

From source file:com.klwork.common.utils.WebUtils.java

/**
 * Header.//from   w  w w.  j a va 2 s  . c o  m
 */
public static void setNoCacheHeader(HttpServletResponse response) {
    //Http 1.0 header
    response.setDateHeader("Expires", 0);
    //Http 1.1 header
    response.setHeader("Cache-Control", "no-cache");
}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ?Header.//  w w  w.  ja v a  2 s.  c  o m
 */
public static void setDisableCacheHeader(HttpServletResponse response) {
    // Http 1.0 header
    response.setDateHeader("Expires", 1L);
    response.addHeader("Pragma", "no-cache");
    // Http 1.1 header
    response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
}

From source file:cn.cdwx.jpa.utils.Servlets.java

/**
 * ??Header.//from   ww w. j  a  v a2 s  .com
 * 
 * @param fileName
 *            ???.
 */
public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {
    // ???
    String encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1);
    response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\"");

}

From source file:com.gc.core.framework.utils.web.ServletUtils.java

/**
 * ??Header./*from  ww w  .j  a  v  a  2s.c o m*/
 * 
 * @param fileName ???.
 */
public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {
    try {
        //???
        String encodedfileName = new String(fileName.getBytes(), "ISO8859-1");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
    } catch (UnsupportedEncodingException e) {
    }
}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ??Header.//from  w ww  . j av  a 2  s  .  co  m
 * 
 * @param fileName
 *            ???.
 */
public static void setFileDownloadHeader(HttpServletResponse response, String fileName) {
    try {
        // ???
        String encodedfileName = new String(fileName.getBytes(), "ISO8859-1");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
    } catch (UnsupportedEncodingException e) {
    }
}

From source file:com.eryansky.common.web.utils.WebUtils.java

/**
 *  Header.// w  w w  . j a v  a2s.  com
 */
public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
    // Http 1.0 header
    response.setDateHeader("Expires", System.currentTimeMillis() + expiresSeconds * 1000);
    // Http 1.1 header
    response.setHeader("Cache-Control", "max-age=" + expiresSeconds);
}

From source file:com.gc.core.framework.utils.web.ServletUtils.java

/**
 *  Header.//w  w w .  j ava  2  s  .c  o  m
 */
public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
    //Http 1.0 header
    response.setDateHeader("Expires", System.currentTimeMillis() + expiresSeconds * 1000);
    //Http 1.1 header
    response.setHeader("Cache-Control", "private, max-age=" + expiresSeconds);
}