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:company.gonapps.loghut.controller.BackupController.java

@RequestMapping(value = "/backup.do", method = RequestMethod.GET)
public void backup(HttpServletResponse response) throws Exception {
    response.setHeader("Content-Type", "application/x-gzip");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + "BACKUP.tar.gz" + "\"");
    postService.backup(response.getOutputStream());
}

From source file:com.nitsoft.ecommerce.CorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with, X-Custom-Header");
    chain.doFilter(req, res);//  w  w w. j  a  v a  2s  .  c o  m
}

From source file:com.cnksi.core.web.utils.Servlets.java

/**
 * ?? If-None-Match Header, Etag?.//from w ww.  ja v a2  s .c om
 * 
 * Etag, checkIfNoneMatchfalse, 304 not modify status.
 * 
 * @param etag ETag.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {

    String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH);
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!"*".equals(headerValue)) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader(HttpHeaders.ETAG, etag);
            return false;
        }
    }
    return true;
}

From source file:com.nguyenle.tellme.travel.webservice.controller.TellmeTravelCORSFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "origin, content-type, accept, x-requested-with");
    chain.doFilter(req, res);/*from   w  w  w.  ja  v a2  s .  com*/
}

From source file:com.sample.ecommerce.SimpleCORSFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST,PUT,PATCH, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    chain.doFilter(req, res);/*from   ww w. ja va 2  s  .  c  o  m*/
}

From source file:Controlador.SimpleCORSFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Content-Type");
    chain.doFilter(req, res);//from w w w.j  av a2s .c  o  m
}

From source file:br.on.daed.services.filters.CacheControlFilter.java

@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HttpServletResponse resp = (HttpServletResponse) response;
    resp.setHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
    resp.setDateHeader("Last-Modified", new Date().getTime());
    resp.setHeader("Cache-Control",
            "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
    resp.setHeader("Pragma", "no-cache");

    chain.doFilter(request, response);/* w  w w.  jav  a2 s.c o m*/
}

From source file:io.github.arven.rs.provider.ApiOriginFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type");
    chain.doFilter(req, res);//from   w ww.  j a  va 2  s . c  o m
}

From source file:hr.softwarecity.osijek.filters.CorsFilter.java

@Override
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) sr1;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    fc.doFilter(sr, sr1);/*from w ww  .  j a v a 2  s . c o  m*/
}

From source file:proyectoFinal.FiltroCorsSimple.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow.Origin", "*");
    response.setHeader("Access-Control-Allow.Methods", "PST,GET,PUT " + "OPTTIONS,DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with-Content-Type");
    chain.doFilter(req, res);//www.  j a  v a2 s  .c  om
}