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:net.lightbody.bmp.proxy.jetty.servlet.SendRedirect.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache,no-store");

    String url = request.getParameter("URL");
    if (url != null && url.length() > 0) {
        response.sendRedirect(url);//from  w ww  .ja  v a 2  s . com
    } else {
        PrintWriter pout = response.getWriter();
        Page page = null;

        try {
            page = new Page();
            page.title("SendRedirect Servlet");

            page.add(new Heading(1, "SendRedirect Servlet"));

            page.add(new Heading(1, "Form to generate Dump content"));
            TableForm tf = new TableForm(response
                    .encodeURL(URI.addPaths(request.getContextPath(), request.getServletPath()) + "/action"));
            tf.method("GET");
            tf.addTextField("URL", "URL", 40, request.getContextPath() + "/dump");
            tf.addButton("Redirect", "Redirect");
            page.add(tf);
            page.write(pout);
            pout.close();
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
        }
    }
}

From source file:com.github.camellabs.iot.cloudlet.document.driver.DriverDocumentCloudlet.java

@Bean
Filter corsFilter() {/*from  w  w  w.  j ava  2  s  .c  o m*/
    return new Filter() {

        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", "Authorization, x-requested-with");
            chain.doFilter(req, res);
        }

        public void init(FilterConfig filterConfig) {
        }

        public void destroy() {
        }

    };
}

From source file:controllers.CCOController.java

@RequestMapping("/getXls")
public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception {
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=CARCOMPOPTION.xls");
    carCompletionOptionService.getXls().write(response.getOutputStream());
}

From source file:org.openxdata.server.servlet.FormSaveServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();

    response.setHeader(OpenXDataConstants.HTTP_HEADER_CONTENT_DISPOSITION,
            OpenXDataConstants.HTTP_HEADER_CONTENT_DISPOSITION_VALUE + session.getAttribute(KEY_FILE_NAME));
    response.setContentType(OpenXDataConstants.HTTP_HEADER_CONTENT_TYPE_XML);

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);
    response.setHeader("Cache-Control", "no-store");

    response.getOutputStream().print((String) session.getAttribute(KEY_FILE_CONTENTS));
}

From source file:com.aistor.common.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*/*from  w w w.  j a  va2s  .c  om*/
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute("validateCode", s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

From source file:controllers.CarOptionValueController.java

@RequestMapping("/getXls")
public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception {
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=options.xls");
    carOptionValueService.getXls().write(response.getOutputStream());
}

From source file:nu.yona.server.rest.LocalizationFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    request = new LocalizationRequestWrapper(properties, request);
    response.setHeader(HttpHeaders.CONTENT_LANGUAGE, Translator.getStandardLocaleString(request.getLocale()));

    chain.doFilter(request, response);/*from  w  w w.  ja  v a2s. c o m*/
}

From source file:com.eryansky.common.web.servlet.ValidateCodeServlet.java

private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    /*/*from  w w w.j  a v  a  2  s  .co  m*/
     * ??
     */
    String width = request.getParameter("width");
    String height = request.getParameter("height");
    if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
        w = NumberUtils.toInt(width);
        h = NumberUtils.toInt(height);
    }

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();

    /*
     * ?
     */
    createBackground(g);

    /*
     * ?
     */
    String s = createCharacter(g);
    request.getSession().setAttribute(SysConstants.SESSION_VALIDATE_CODE, s);

    g.dispose();
    OutputStream out = response.getOutputStream();
    ImageIO.write(image, "JPEG", out);
    out.close();

}

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

@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String path = request.getServletPath();
    if (path.matches("^/astro/.*$")) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    }//  www  .jav a  2 s .c  o m
    chain.doFilter(request, response);
}

From source file:no.dusken.aranea.web.control.PictureController.java

public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws PageNotFoundException {

    // this content does not change that often, allow two hours cache
    response.setHeader("Cache-Control", "max-age=72000");

    Map<String, Object> map = new HashMap<String, Object>();

    if (request.getParameter("ID") != null) {
        Long imageID = ServletRequestUtils.getLongParameter(request, "ID", 0L);
        Image i = imageService.getEntity(imageID);
        if (i != null) {
            map.put("image", i);
        } else {// w  w  w .  j  av a  2s  .c  om
            //Throwing exception so this can be threated as a 404 error on a higher level
            log.warn("Did not find image with id {}", imageID);
            throw new PageNotFoundException("image with id=" + imageID);
        }
    }

    return new ModelAndView("no/dusken/aranea/base/web/picture/view", map);
}