Example usage for javax.servlet.http HttpServletResponse setStatus

List of usage examples for javax.servlet.http HttpServletResponse setStatus

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setStatus.

Prototype

public void setStatus(int sc);

Source Link

Document

Sets the status code for this response.

Usage

From source file:cc.sion.core.web.Servlets.java

/**
 * ??If-Modified-Since Header, ?./*from   w w  w  . ja va  2s. c o  m*/
 *
 * , checkIfModifyfalse ,304 not modify status.
 *
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < (ifModifiedSince + 1000))) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:memedb.httpd.MemeDBHandler.java

public static void sendError(HttpServletResponse response, String errMsg, String reason, JSONObject status,
        int statusCode, Logger log) throws IOException {
    response.setStatus(statusCode);
    response.setContentType(TEXT_PLAIN_MIMETYPE);
    try {/*from   www.j ava 2 s.co  m*/
        new JSONWriter(response.getWriter()).object().key("ok").value(false).key("error").value(errMsg)
                .key("reason").value(reason).key("status").value(status).endObject();
    } catch (JSONException e) {
        if (log != null)
            log.error(e);
        throw new IOException(e);
    }
}

From source file:cn.com.qiqi.order.utils.Servlets.java

/**
 * ??If-Modified-Since Header, ?.//  w ww.ja v a 2 s .c om
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

private static void createNewSession(@NotNull HttpServletRequest request,
        @NotNull HttpServletResponse response) {
    request.getSession(true);/*from ww w  .  ja  v  a 2 s. c o m*/
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.cnksi.core.web.utils.Servlets.java

/**
 * ??If-Modified-Since Header, ?.//  ww w.  java  2  s.  com
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {

    long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:com.vmware.identity.openidconnect.server.Shared.java

public static void writeJSONResponse(HttpServletResponse httpServletResponse, int statusCode,
        JSONObject jsonObject) throws IOException {
    Validate.notNull(httpServletResponse, "httpServletResponse");
    Validate.notNull(jsonObject, "jsonObject");

    PrintWriter writer = null;//from www .  j  a va 2 s.  c  o m
    try {
        httpServletResponse.setStatus(statusCode);
        httpServletResponse.setContentType("application/json");
        writer = httpServletResponse.getWriter();
        writer.print(jsonObject.toString());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:com.pactera.edg.am.metamanager.extractor.util.AntZip.java

public static void zipFile(String inputFileName, HttpServletResponse response) {
    try {/*from w w  w. j ava  2s . co m*/
        response.setContentType("text/plain;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=data.zip");
        response.setStatus(HttpServletResponse.SC_OK); //??
        OutputStream output = response.getOutputStream();
        ZipOutputStream zipOut = new ZipOutputStream(output);
        zip(zipOut, new File(inputFileName), "");
        if (zipOut != null)
            zipOut.close();
        if (output != null)
            output.close();
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    } finally {

    }

}

From source file:ch.ralscha.extdirectspring.util.ExtDirectSpringUtil.java

/**
 * Checks etag and sends back HTTP status 304 if not modified. If modified sets
 * content type and content length, adds cache headers (
 * {@link #addCacheHeaders(HttpServletResponse, String, Integer)}), writes the data
 * into the {@link HttpServletResponse#getOutputStream()} and flushes it.
 *
 * @param request the HTTP servlet request
 * @param response the HTTP servlet response
 * @param data the response data//  www  .ja v a 2  s.  co m
 * @param contentType the content type of the data (i.e.
 * "application/javascript;charset=UTF-8")
 * @throws IOException
 */
public static void handleCacheableResponse(HttpServletRequest request, HttpServletResponse response,
        byte[] data, String contentType) throws IOException {
    String ifNoneMatch = request.getHeader("If-None-Match");
    String etag = "\"0" + DigestUtils.md5DigestAsHex(data) + "\"";

    if (etag.equals(ifNoneMatch)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }

    response.setContentType(contentType);
    response.setContentLength(data.length);

    addCacheHeaders(response, etag, 6);

    @SuppressWarnings("resource")
    ServletOutputStream out = response.getOutputStream();
    out.write(data);
    out.flush();
}

From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java

/**
 * Calls writeResponse() and sets the response status to ok
 * @param data/*from ww  w  . j ava2s. co  m*/
 *          Object which should be serialized and written to the response
 * @param request
 * @param response
 */
public static void doOkResponse(Object data, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    write(data, response);
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.aaasec.sigserv.csspserver.SpServlet.java

private static void nullResponse(HttpServletResponse response) {
    try {// w w  w .  jav a  2s. c om
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        response.getWriter().write("");
        response.getWriter().close();
    } catch (IOException ex) {
        Logger.getLogger(SpServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}