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.jaspersoft.jasperserver.war.StaticFilesCacheControlFilter.java

private void setHeaders(HttpServletRequest request, HttpServletResponse response) {
    try {/*  w  w  w .  j a  va  2  s.  co  m*/
        response.setHeader("Cache-Control", "max-age=" + expiresInSecs + ", public");
        response.setHeader("Pragma", "");
        response.setHeader("Expires",
                DATE_FORMAT.format(new Date(new Date().getTime() + expiresInSecs * 1000)));

    } catch (Exception ex) {
        log.warn("Cannot set cache headers", ex);
    }
}

From source file:biz.taoconsulting.dominodav.methods.OPTIONS.java

/**
 * (non-Javadoc)//from  w w  w  . j  av a2s.c o m
 * 
 * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#writeInitialHeader()
 */
protected void writeInitialHeader() {
    HttpServletResponse resp = this.getResp();
    // Caldav header TODO: do we need to complete header methods for webDAV
    // with access-control, calendar-access?
    resp.setHeader("DAV", "1,2");
    resp.setHeader("MS-Author-Via", "DAV"); // needed so Office knows what
    // to do

}

From source file:com.attribyte.essem.BasicAuth.java

@Override
public void sendUnauthorized(final String index, final HttpServletResponse response) throws IOException {
    response.setHeader(WWW_AUTHENTICATE_HEADER, "Basic realm=" + "\"" + index + "\"");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}

From source file:RedirectNewLocation.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();

    response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", "http://www.java2s.com");

    response.setContentType("text/html");
    return;/*  w  ww . j a  v  a  2s .  c  om*/
}

From source file:it.drwolf.ridire.servlet.TmpResourcesServlet.java

public void getTmpFile(String filename) {
    HttpServletResponse response = (HttpServletResponse) this.extCtx.getResponse();
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    try {//  w w  w.  j a v a 2s.  c  om
        String ret = FileUtils.readFileToString(
                new File(
                        System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + filename),
                "UTF-8");
        response.getOutputStream().print(ret);
        response.getOutputStream().flush();
        // FacesContext.getCurrentInstance().responseComplete();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.controlj.green.istat.web.TreeServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setHeader("Expires", "Wed, 01 Jan 2003 12:00:00 GMT");
    resp.setHeader("Cache-Control", "no-cache");
    ServletOutputStream out = resp.getOutputStream();
    try {/*from   w  ww  .  j  a v a  2 s.co  m*/
        writeLevel(out, req.getParameter(LOCATION_PARAM), req);
    } catch (Exception e) {
        Logging.LOGGER.println("Error getting tree info");
        e.printStackTrace(Logging.LOGGER);
        throw new ServletException(e);
    }
    out.flush();
    /*
    out.println("[");
    out.println("{ display:'Main Conf Room', id:'mainconf'},");
    out.println("{ display:'Board Room', id:'boardroom'},");
    out.println("{ display:'Room 235', id:'room235'}");
    out.println("]");
    */
}

From source file:ee.pri.rl.blog.web.servlet.FileDownloadServlet.java

private void sendNotModified(String calculatedTag, HttpServletResponse resp) {
    resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
    resp.setHeader("ETag", calculatedTag);
}

From source file:org.apereo.openlrs.OpenLRSAuthenticationFilter.java

private void unauthorized(HttpServletResponse response, String message, String type) throws IOException {
    response.setHeader("WWW-Authenticate", type + " realm=\"OpenLRS\"");
    response.sendError(401, message);/*from www.ja  v  a  2s . c o m*/
}

From source file:com.adito.extensions.actions.GetApplicationFileAction.java

private void sendFile(InputStream in, long length, HttpServletResponse response) throws IOException {
    Util.noCache(response);//from  ww  w.  j a va 2 s  .  c  om

    response.setHeader("Content-type", "application/octet-stream");
    response.setContentLength((int) length);
    try {

        Util.copy(in, response.getOutputStream());

    } catch (IOException ex) {
    } finally {
        Util.closeStream(in);
        Util.closeStream(response.getOutputStream());
    }

}

From source file:com.iisigroup.cap.component.impl.FileDownloadResult.java

public void respondResult(ServletResponse response) {
    InputStream in = null;/*from w w w. ja v  a  2  s.co m*/
    OutputStream output = null;
    try {
        response.setContentType(_contentType);
        if (_outputName != null && response instanceof HttpServletResponse) {
            HttpServletResponse resp = (HttpServletResponse) response;
            resp.setHeader("Content-Disposition", "attachment;filename=\"" + _outputName + "\"");
            resp.setHeader("Cache-Control", "public");
            resp.setHeader("Pragma", "public");
        }
        output = response.getOutputStream();
        File file = new File(_file);
        int length = -1;
        // Stream to the requester.
        byte[] bbuf = new byte[1024 * 1024];
        int len = 0;
        in = new FileInputStream(file);
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            output.write(bbuf, 0, length);
            len += length;
        }
        response.setContentLength(len);
        output.flush();
    } catch (Exception e) {
        throw new CapException(e, getClass());
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(output);
    }

}