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.surfs.storage.web.controller.storage.LoginController.java

@RequestMapping(method = RequestMethod.GET, value = "/test.do")
@ResponseBody//from   w  ww  .j  a v a  2  s  .co m
public void test(HttpServletRequest request, HttpServletResponse response) {
    try {
        response.setHeader("Content-Type", "text/event-stream");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().println("data:" + new Date().toString());
        response.getWriter().println();
        response.getWriter().flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:se.skltp.cooperation.web.rest.v1.filter.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", "GET");
    response.setHeader("Access-Control-Max-Age", "3600");
    chain.doFilter(req, res);//from   www.j  a  va 2  s .  c om
}

From source file:codes.thischwa.c5c.requestcycle.response.mode.Download.java

@Override
@JsonIgnore//from   w w w.ja v  a 2 s. c o m
public void write(HttpServletResponse resp) throws IOException {
    resp.setHeader("Content-Type", "application/x-download");
    resp.setHeader("Content-Transfer-Encoding", "Binary");
    resp.setHeader("Content-Length", String.valueOf(contentLength));
    resp.setHeader("Content-Disposition",
            String.format("attachment; filename=\"%s\"", FilenameUtils.getName(fullPath)));
    IOUtils.copy(in, resp.getOutputStream());
}

From source file:com.hillert.botanic.filter.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);/* ww  w . j ava2s. c  o  m*/
}

From source file:com.jaspersoft.jasperserver.ps.CORSHandler.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");
    response.setHeader("X-Frame-Options", "ALLOW");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    chain.doFilter(req, res);//from w  w  w.  j  av a  2 s .  c  o m
}

From source file:info.losd.galen.api.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");
    chain.doFilter(req, res);/*  w  w  w.ja  va  2 s .  co m*/
}

From source file:io.apicurio.studio.fe.servlet.servlets.ReadyServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from w w w  . j  a va  2  s.c  om*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setHeader("Content-Type", "application/json");
    IOUtils.copy(new StringReader("{ \"up\": true }"), resp.getOutputStream());
    resp.getOutputStream().flush();
}

From source file:org.khmeracademy.btb.auc.pojo.configuration.CORSFilter.java

/**
 *
 * @param req// www .  ja va 2 s  .  c om
 * @param res
 * @param chain
 * @throws IOException
 * @throws ServletException
  @Component
*/

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, PUT, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
    chain.doFilter(req, res);
}

From source file:org.unitec.maven.FiltroCorsSimple.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,PUT" + "OPTION,DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Content-Type");
    chain.doFilter(req, res);// ww w.  j  ava2s . com

}

From source file:eu.paasword.filter.CORSFilter.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, PUT, 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);/*w  w  w. j av  a 2s.  c om*/
}