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:at.porscheinformatik.common.spring.web.extended.template.ResourceControllerBase.java

protected void handleCaching(HttpServletResponse response, boolean noCaching) {
    if (appConfig.isOptimizeResources() && !noCaching) {
        response.setHeader("Cache-Control", "public, max-age=31536000");
        response.setHeader("Pragma", "cache");
    } else {/*from  www .  j a v a2s  . c  om*/
        response.setHeader("Cache-Control", "no-store, max-age=0, must-revalidate");
        response.setHeader("Pragma", "no-cache");
    }
}

From source file:com.glodon.paas.document.web.controller.ProjectTemplateController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView getTemplates(@RequestParam(value = "includePublic", required = false) String hasCommon,
        HttpServletRequest request, HttpServletResponse response, ModelMap model) {
    response.setHeader("Cache-Control", "no-cache");
    User user = getUser();//from   ww  w . j  a v  a2 s.  co  m
    List<ProjectTemplate> result = projectService.getAllTemplates(user.getIdStr(), hasCommon);
    model.addAttribute(StringConst.ITEMS, result);
    return ModelViewGenerator.generate(ViewNames.VIEW_NAME_PROJECT_TEMPLATES_GET, model);
}

From source file:com.xhsoft.framework.common.filter.SessionUpcFilter.java

public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = ((HttpServletRequest) req);
    HttpSession session = (request).getSession();
    //UserInfo user=(UserInfo)session.getAttribute(SessionCons.CURRENT_ACCOUNT);

    try {/*from w  ww  .ja  v  a2s . co  m*/
        /*if(user!=null){
          LoginUtil.setLoginUser(request, user);
        }*/

        HttpServletResponse httpResponse = (HttpServletResponse) response;
        httpResponse.setHeader("Pragma", "No-cache");
        httpResponse.setHeader("Cache-Control", "no-cache");
        httpResponse.setDateHeader("Expires", 0);
        chain.doFilter(request, response);
    } catch (IOException ex) {
        logger.error(request.getRemoteAddr() + " io error : " + ex);
    } catch (Exception de) {
        de.printStackTrace();
    }
    logger.debug("User Filter end!");
}

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

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

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

    String format = request.getParameter("format");
    response.setContentType(format.equalsIgnoreCase("pdf") ? OpenXDataConstants.HTTP_HEADER_CONTENT_TYPE_PDF
            : OpenXDataConstants.HTTP_HEADER_CONTENT_TYPE_TEXT_HTML);

    String fileName = request.getParameter("name");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

    Integer reportId = Integer.parseInt(request.getParameter("reportId"));
    response.getOutputStream()/*from  ww  w . ja  va 2 s .  com*/
            .write(reportService.getReportDataBytes(request.getRequestURI(), reportId, format));
}

From source file:com.excel.ExcelView.java

@Override
protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ExcelModel em = (ExcelModel) model.get("myModel");

    response.setHeader("Content-Disposition", "attachment; filename=\"" + em.getFileName() + ".xls\"");

    HSSFSheet excelSheet = workbook.createSheet(em.getFileName());

    setExcelHeader(excelSheet, em.getTitles());
    setExcelRows(excelSheet, em.getContents());
}

From source file:com.ewcms.component.comment.web.CounterServlet.java

private void initResponseHeader(final HttpServletResponse response, final String encoding) {
    response.setHeader("Content-Language", "zh-CN");
    String fullContentType = JSON_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:codes.thischwa.c5c.requestcycle.response.mode.Prieview.java

@Override
@JsonIgnore/*ww w  .ja v  a2  s .  c o m*/
public void write(HttpServletResponse resp) throws IOException {
    String contentType = contentTypes.getContentTypeFor(fullPath);
    resp.setHeader("Content-Type", contentType);
    resp.setHeader("Content-Length", String.valueOf(contentLength));
    IOUtils.copy(in, resp.getOutputStream());
}

From source file:nl.edia.sakai.tool.skinmanager.download.SkinDownloadView.java

/**
 * @param response/*from  ww w . ja v  a 2  s .  co  m*/
 * @param myName
 */
protected void setHeaders(HttpServletResponse response, String myName) {
    response.setContentType(getContentType());
    response.setHeader("Content-Disposition", "attachment; filename=" + myName + ".zip");
}

From source file:org.nsesa.editor.gwt.an.amendments.server.service.XMLExportService.java

@Override
public void export(AmendmentContainerDTO object, HttpServletResponse response) throws IOException {
    try {//w  ww  .j a v a2s .c om
        response.setContentType("text/xml");
        response.setHeader("Content-Disposition",
                "attachment;filename=" + object.getAmendmentContainerID() + ".xml");
        response.setCharacterEncoding("UTF8");

        byte[] bytes = object.getBody().getBytes("utf-8");
        IOUtils.copy(new ByteArrayInputStream(bytes), response.getOutputStream());
        response.setContentLength(bytes.length);
        response.flushBuffer();
    } catch (IOException e) {
        throw new RuntimeException("Failed to xml export", e);
    }
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "es");

    Locale locale = new Locale("es", "");
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    fmt.setTimeZone(TimeZone.getDefault());

    out.println("En Espa\u00f1ol:");
    out.println("\u00a1Hola Mundo!");
    out.println(fmt.format(new Date()));
}