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.thoughtworks.go.server.controller.actions.XmlAction.java

public ModelAndView respond(HttpServletResponse response) throws Exception {
    if (md5 != null) {
        response.setHeader(X_CRUISE_CONFIG_MD5, md5);
    }/*from w  w  w .  j  av a2 s .  c  o m*/
    return super.respond(response);
}

From source file:com.lcw.one.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");

    /*/* w w w. j a va2 s . c  o  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();

}

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * write the http header in the response
 * @param request the httpServletRequest
 * @param response the http response/*from w  ww.  ja va  2 s  . c  om*/
 * @param strFileName the name of the file who must insert in the response
 * @param strFileExtension the file extension
 */
public static void addHeaderResponse(HttpServletRequest request, HttpServletResponse response,
        String strFileName, String strFileExtension) {
    response.setHeader("Content-Disposition", "attachment ;filename=\"" + strFileName + "\"");

    if (strFileExtension.equals("csv")) {
        response.setContentType("application/csv");
    } else {
        String strMimeType = request.getSession().getServletContext().getMimeType(strFileName);

        if (strMimeType != null) {
            response.setContentType(strMimeType);
        } else {
            response.setContentType("application/octet-stream");
        }
    }

    response.setHeader("Pragma", "public");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate,post-check=0,pre-check=0");
}

From source file:gateway.controller.util.CorsFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.setHeader("Access-Control-Allow-Headers", "authorization, content-type");
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "*");
    response.setHeader("Access-Control-Max-Age", "36000");
    filterChain.doFilter(request, response);
}

From source file:com.indeed.imhotep.web.BashScriptServlet.java

@RequestMapping("/iql.sh")
@ResponseBody/*from  w ww .  j  a v a2s.c om*/
protected String doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setHeader("content-disposition", "attachment; filename=iql.sh");
    final String server = req.getServerName();
    final String protocol;
    if (server.contains("qa.indeed") || server.contains("stage.indeed") || server.contains("indeed.com")) {
        protocol = "https://";
    } else {
        protocol = "http://";
    }

    final URL scriptResourceURL = Resources.getResource("iql.sh");
    final String script = Resources.toString(scriptResourceURL, Charsets.UTF_8);
    final String serverURLVariable = "SERVER_URL=" + protocol + server + ":" + req.getServerPort()
            + req.getContextPath() + "/query\n";
    return serverURLVariable + script;
}

From source file:edu.wisc.web.util.NoCacheHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
    response.setDateHeader("Expires", 0);
    filterChain.doFilter(request, response);
}

From source file:simplestorage.hashtable.JsonView.java

@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType("text/plain");
    response.setHeader("Cache-Control", "no-cache");
    String json = model.get("responseJson").toString();
    ServletOutputStream out = response.getOutputStream();
    out.print(json);/* ww  w.  ja  v  a2 s .co  m*/
    out.close();
}

From source file:com.github.fauu.natrank.web.filter.CORSFilter.java

@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        FilterChain filterChain) throws ServletException, IOException {
    httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
    httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
    httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
    httpServletResponse.setHeader("Access-Control-Allow-Headers", "x-requested-with");

    filterChain.doFilter(httpServletRequest, httpServletResponse);
}

From source file:com.indeed.imhotep.web.TokenizeController.java

@RequestMapping("/tokenize")
@ResponseBody//from  w w  w  .jav  a  2 s.c  o  m
protected void handleTokenize(@RequestParam("q") String query, HttpServletResponse resp) throws IOException {

    resp.setHeader("Access-Control-Allow-Origin", "*");
    try {
        final List<Token> tokens = TerminalParser.LEXER.parse(query);
        final ServletOutputStream outputStream = resp.getOutputStream();
        resp.setContentType(MediaType.APPLICATION_JSON_VALUE);
        final ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        final ObjectNode jsonRoot = mapper.createObjectNode();
        final ArrayNode tokenArrayNode = jsonRoot.arrayNode();
        jsonRoot.put("tokens", tokenArrayNode);
        for (Token token : tokens) {
            final ObjectNode tokenNode = tokenArrayNode.objectNode();
            final String text = token.value() instanceof Tokens.Fragment
                    ? ((Tokens.Fragment) token.value()).text()
                    : (String) token.value();
            final String tag = token.value() instanceof Tokens.Fragment
                    ? ((Tokens.Fragment) token.value()).tag().toString()
                    : "STRING";

            tokenNode.put("text", text);
            tokenNode.put("index", token.index());
            tokenNode.put("length", token.length());
            tokenNode.put("tag", tag);
            tokenArrayNode.add(tokenNode);
        }

        mapper.writeValue(outputStream, jsonRoot);
        outputStream.close();

    } catch (Throwable e) {
        QueryServlet.handleError(resp, true, e, false, false);
    }
}

From source file:com.fpmislata.banco.presentacion.CreditoController.java

private void noCache(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Cache-Control", "no-cache");
}