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.ewcms.component.counter.web.CounterServlet.java

private void initResponseHeader(final HttpServletResponse response, final String encoding) {
    response.setHeader("Content-Language", "zh-CN");
    String fullContentType = JS_TYPE + ";charset=" + encoding;
    response.setContentType(fullContentType);
    //set on cache
    ///Http 1.0 header
    response.setDateHeader("Expires", 0);
    response.addHeader("Pragma", "no-cache");
    //Http 1.1 header
    response.setHeader("Cache-Control", "no-cache");
}

From source file:com.enonic.cms.server.service.servlet.CmsDispatcherServlet.java

@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setHeader("Allow", StringUtils.join(ALLOWED_HTTP_METHODS, ","));
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.ar.dev.tierra.api.config.SimpleCORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) resp;
    HttpServletRequest request = (HttpServletRequest) req;
    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, authorization, Content-Type, Authorization, credential, X-XSRF-TOKEN");

    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {//from ww w .j av  a2s  . c  o  m
        chain.doFilter(req, resp);
    }

}

From source file:com.fishcart.delivery.service.OrderInformer.java

@RequestMapping(value = "/orderhistory", method = { RequestMethod.POST, RequestMethod.GET }, produces = {
        "application/text" })
public void getOrderHistory(@RequestParam(value = "date") String date, HttpServletResponse response)
        throws IOException {
    String data = generator.getOrderHistory(date);
    response.setHeader("Content-Disposition", "attachment; filename=report.csv");
    IOUtils.copy(IOUtils.toInputStream(data, "UTF-8"), response.getOutputStream());
    response.flushBuffer();// w w  w.j  a  va  2 s .  c o m
}

From source file:org.fishwife.jrugged.spring.StatusController.java

private void writeOutCurrentStatusInResponseBody(HttpServletResponse resp, Status currentStatus)
        throws IOException {
    resp.setHeader("Content-Type", "text/plain;charset=utf-8");
    String body = currentStatus + "\n";
    byte[] bytes = body.getBytes();
    resp.setHeader("Content-Length", bytes.length + "");
    OutputStream out = resp.getOutputStream();
    out.write(bytes);//ww w . j av  a  2  s  .  c o  m
    out.flush();
    out.close();
}

From source file:cn.vlabs.clb.api.io.impl.ServletOutputStream.java

public ServletOutputStream(String agent, HttpServletResponse response) {
    this.agent = agent;
    this.response = response;
    response.setHeader("Pragma", "");
    response.setHeader("Cache-Control", "");
}

From source file:org.openbaton.nfvo.security.authentication.SimpleCorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "x-requested-with, authorization, content-type, Cache-Control");

    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {//  w ww .ja va  2 s  .c  o  m
        chain.doFilter(req, res);
    }
}

From source file:org.nubomedia.marketplace.api.SimpleCorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;
    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",
            "Auth-token, x-requested-with, authorization, content-type, origin");

    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {/* www .  j  ava  2  s  .co  m*/
        chain.doFilter(req, res);
    }
}

From source file:com.starr.smartbuilds.controller.BuildController.java

@RequestMapping(method = { RequestMethod.GET })
public String getBuild(Model model, HttpServletRequest req, HttpServletResponse resp)
        throws IOException, ParseException {
    resp.setHeader("Access-Control-Allow-Origin", "*");
    Build build = new Build();
    Long buildId = 0L;/*from  w  w  w.j  a va2  s.c  o m*/
    String p = req.getParameter("id");
    if (p != null || !p.equals("")) {
        buildId = Long.parseLong(p);
        try {
            HttpSession session = req.getSession();

            build = buildDAO.getBuild(buildId);
            model.addAttribute("author", build.getUser());
            model.addAttribute("build", build);
            model.addAttribute("champion", build.getChampion().getKeyChamp());
            model.addAttribute("blocks", buildService.parseBlocks(build.getBlocks()));
            model.addAttribute("download", fileService.getFile(build, session.getServletContext()));

            User user = (User) session.getAttribute("user");
            if (user == null) {
                model.addAttribute("authMsg", "<a href='./auth'>Log in</a>");
                model.addAttribute("exitReg", "<a href='./reg'>Register</a>");
            } else {
                model.addAttribute("authMsg", "Hello," + user.getSummonerName() + "!");
                model.addAttribute("exitReg", "<a href='./auth/exit'>Exit</a>");
                model.addAttribute("createbuild",
                        "<li><a href='./add' style='color: #deff00;'>Create Build</a></li>");
            }
        } catch (NullPointerException ex) {
            resp.sendRedirect("/");
        }

        return "build";
    } else {
        System.out.println("param--" + p);
        resp.sendRedirect("./");

    }

    return "build";
}

From source file:com.nzion.web.PdfServlet.java

@Override
protected void service(HttpServletRequest reqqest, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/plm");
    response.setHeader("Content-Disposition", "attachment; filename=2D.plm");
    ServletOutputStream outputStream = response.getOutputStream();
    BufferedInputStream bufferedInputStream = new BufferedInputStream(
            new FileInputStream(new File("F:\\PDF_Stamping\\2D\\2D.zip")));
    IOUtils.copy(bufferedInputStream, outputStream);
    bufferedInputStream.close();/*from  www  . jav  a 2s . c om*/
    outputStream.flush();
}