writes the Bad Request String in the Servlet response if condition falis

@param res a {@link javax.servlet.http.HttpServletResponse} object
@throws IOException
355509
private void badRequest(HttpServletResponse res) throws IOException {
		res.setContentType("text/html");
		PrintWriter pw = res.getWriter();
		pw.write(BAD_REQUEST);
		pw.close();
	}
1099898
public void processException(HttpServletRequest req, HttpServletResponse res) throws IOException
    {
        if (redirectURL != null)
        {
            res.sendRedirect(redirectURL);
            return;
        }
        
        if (message == null)
        {
            res.sendError(statusCode);
        }
        else
        {
            res.sendError(statusCode, message);
        }
    }
589297
public static void post(URL url, String params) throws IOException {
        URLConnection conn = url.openConnection();
        if (conn instanceof HttpURLConnection) {
            ((HttpURLConnection) conn).setRequestMethod("POST");
            conn.setRequestProperty("Content-Type" , "application/json");
        }
        OutputStreamWriter writer = null;
        try {
            conn.setDoOutput(true);
            writer = new OutputStreamWriter(conn.getOutputStream(),
                    Charset.forName("UTF-8"));
            // write parameters
            writer.write(params);
            writer.flush();
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
1026006
@Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (req.getRequestURI().endsWith("upload")) {
      uploadCallback(req, resp);
    } else {
      resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
  }
284770
public void sendResponse(HttpResponse resp, boolean close) throws IOException {
		StringBuilder header = new StringBuilder();
		header.append("HTTP/1.1").append(' ').append(resp.getStatus().getCode()).append(' ').append(resp.getStatus());
		header.append('\r').append('\n');
		// Set the content type header if it's not already set
		if (!resp.getHeaders().containsKey(HttpHeader.CONTENT_TYPE)) {
			resp.addHeader(HttpHeader.CONTENT_TYPE, "text/html; charset=utf-8");
		}
		// Set the content length header if it's not already set
		if (!resp.getHeaders().containsKey(HttpHeader.CONTENT_LENGTH)) {
			resp.addHeader(HttpHeader.CONTENT_LENGTH, resp.getResponseLength());
		}
		// Copy in the headers
		for (Entry<String, List<Object>> entry : resp.getHeaders().entrySet()) {
			String headerName = HttpUtil.capitalizeHeader(entry.getKey());
			for (Object o : entry.getValue()) {
				header.append(headerName);
				header.append(':').append(' ');
				header.append(o);
				header.append('\r').append('\n');
			}
		}
		header.append('\r').append('\n');
		// Write the header
		output.write(header.toString().getBytes("UTF-8"));

		// Ignore the body for headers and no content
		if (request != null && request.getMethod() == HttpMethod.HEAD || resp.getStatus() == HttpStatus.NO_CONTENT) {
			if (resp.getResponse() instanceof InputStream) {
				((InputStream) resp.getResponse()).close();
			}
		} else {
			// Responses can be InputStreams or Strings
			if (resp.getResponse() instanceof InputStream) {
				// InputStreams will block the session thread (No big deal) and send
				// data without loading it into memory
				InputStream res = resp.getResponse();
				try {
					long remaining = resp.getResponseLength();
					// Write the body
					byte[] buffer = new byte[1024];
					while (remaining > 0) {
						int read = res.read(buffer, 0, remaining > buffer.length ? buffer.length : (int) remaining);
						if (read == -1) {
							break;
						}

						output.write(buffer, 0, read);

						remaining -= read;
					}
				} finally {
					res.close();
				}
			} else if (resp.getResponse() instanceof String) {
				String responseString = resp.getResponse();
				output.write(responseString.getBytes("UTF-8"));
			} else if (resp.getResponse() instanceof byte[]) {
				output.write((byte[]) resp.getResponse());
			}
		}
		// Close it if required.
		if (close) {
			socket.close();
		}
	}

	/**
	 * Send an HttpStatus
	 *
	 * @param status The status to send
	 * @throws IOException If an error occurred while sending
	 */
	public void sendError(HttpStatus status) throws IOException {
		sendResponse(new HttpResponse(status, status.toString()));
	}

	/**
	 * Send an HttpStatus with the specified error message
	 *
	 * @param status The status to send
	 * @param message The error message to send
	 * @throws IOException If an error occurred while sending
	 */
	public void sendError(HttpStatus status, String message) throws IOException {
		sendResponse(new HttpResponse(status, status.toString() + ':' + message));
	}

	/**
	 * Get the remote address from this session
	 *
	 * @return The remote address
	 */
	public InetSocketAddress getRemoteAddress() {
		return (InetSocketAddress) socket.getRemoteSocketAddress();
	}
}
399259
public static void jfFrontConsume(HttpServletResponse resp, Map<String, String> reqData) throws IOException {
		String html = AcpService.createAutoFormHtml(SDKConfig.getConfig().getJfFrontRequestUrl(), reqData, "UTF-8");
		resp.getWriter().write(html);
	}
1168659
public void write(String lineDocument,
            final IAsyncHandler<InfluxException> failureHandler) {
        // Make request to influx
        IHttpClientRequest request = httpClient.request(writeUrl.toString(), HttpMethod.POST,
                result -> {
                    if (result.isError() || result.getResult().getResponseCode() < 200
                            || result.getResult().getResponseCode() > 299) {
                        failureHandler.handle(new InfluxException(result.getResult()));
                    }
                });
        // For some reason Java's URLEncoding doesn't seem to be parseable by influx?
        //request.addHeader("Content-Type", "application/x-www-form-urlencoded");
        request.addHeader("Content-Type", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
        request.write(lineDocument, StandardCharsets.UTF_8.name());
        request.end();
    }
846226
public void handlePut(HttpServletRequest request, HttpServletResponse response, String pathInContext, Resource resource) throws ServletException, IOException
    {
        boolean exists = resource != null && resource.exists();
        if (exists && !passConditionalHeaders(request, response, resource))
            return;

        if (pathInContext.endsWith("/"))
        {
            if (!exists)
            {
                if (!resource.getFile().mkdirs())
                    response.sendError(HttpResponse.__403_Forbidden, "Directories could not be created");
                else
                {
                    response.setStatus(HttpResponse.__201_Created);
                    response.flushBuffer();
                }
            }
            else
            {
                response.setStatus(HttpResponse.__200_OK);
                response.flushBuffer();
            }
        }
        else
        {
            try
            {
                int toRead = request.getContentLength();
                InputStream in = request.getInputStream();
                OutputStream out = resource.getOutputStream();
                if (toRead >= 0)
                    IO.copy(in, out, toRead);
                else
                    IO.copy(in, out);
                out.close();

                response.setStatus(exists ? HttpResponse.__200_OK : HttpResponse.__201_Created);
                response.flushBuffer();
            }
            catch (Exception ex)
            {
                log.warn(LogSupport.EXCEPTION, ex);
                response.sendError(HttpResponse.__403_Forbidden, ex.getMessage());
            }
        }
    }
915638
@Override
    protected final void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (!support.isLegal(request)) {
            return;
        }
        //设置响应编码格式
        response.setCharacterEncoding("UTF-8");
        String resp = support.processRequest(request);
        PrintWriter pw = response.getWriter();
        pw.write(resp);
        pw.flush();
        pw.close();
    }
1269222
protected void writeJSON(final HttpServletResponse resp, final Object obj)
      throws IOException {
    writeJSON(resp, obj, false);
  }
686681
public static void write(HttpServletResponse response, InputStream in, int bufferSize) {
		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			IoUtil.copy(in, out, bufferSize);
		} catch (IOException e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(out);
			IoUtil.close(in);
		}
	}
348819
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        try {
            res.setDateHeader("Expires", 0);        // Make sure the browser never caches these requests
            res.setHeader("Pragma", "No-cache");
            res.setHeader("Cache-Control", "no-cache");
            m_servletTask.doProcess(this, req, res, null);
        } catch (Throwable ex)  {
            ex.printStackTrace();
        }
    }
449705
public void doProcess(HttpServletRequest req, HttpServletResponse res) 
        throws ServletException, IOException
    {
        ServletTask servletTask = new ServletTask(this, BasicServlet.SERVLET_TYPE.HTML);
        try {
            this.addBrowserProperties(req, servletTask);
            servletTask.doProcess(this, req, res, null);
        } catch (ServletException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        } finally {
            servletTask.free();
        }
    }
1293145
public void service( final WebdavRequest req, final WebdavResponse resp )
        throws WebdavException, IOException
    {

        final String methodName = req.getMethod();
        ITransaction transaction = null;
        boolean needRollback = false;

        if ( LOG.isTraceEnabled() )
        {
            debugRequest( methodName, req );
        }

        try
        {
            final Principal userPrincipal = req.getUserPrincipal();
            transaction = store.begin( userPrincipal );
            needRollback = true;
            store.checkAuthentication( transaction );
            resp.setStatus( WebdavStatus.SC_OK );

            WebdavMethod methodExecutor = null;
            try
            {
                methodExecutor = _methodMap.get( methodName );
                if ( methodExecutor == null )
                {
                    methodExecutor = _methodMap.get( "*NO*IMPL*" );
                }

                LOG.info( "Executing: " + methodExecutor.getClass()
                                                        .getSimpleName() );
                methodExecutor.execute( transaction, req, resp );

                store.commit( transaction );
                needRollback = false;
            }
            catch ( final IOException e )
            {
                final java.io.StringWriter sw = new java.io.StringWriter();
                final java.io.PrintWriter pw = new java.io.PrintWriter( sw );
                e.printStackTrace( pw );
                LOG.error( "IOException: " + sw.toString() );
                resp.sendError( WebdavStatus.SC_INTERNAL_SERVER_ERROR );
                store.rollback( transaction );
                throw new WebdavException( "I/O error executing %s: %s", e, methodExecutor.getClass()
                                                                                          .getSimpleName(), e.getMessage() );
            }

        }
        catch ( final UnauthenticatedException e )
        {
            resp.sendError( WebdavStatus.SC_FORBIDDEN );
        }
        catch ( final WebdavException e )
        {
            final java.io.StringWriter sw = new java.io.StringWriter();
            final java.io.PrintWriter pw = new java.io.PrintWriter( sw );
            e.printStackTrace( pw );
            LOG.error( "WebdavException: " + sw.toString() );
            throw e;
        }
        catch ( final Exception e )
        {
            final java.io.StringWriter sw = new java.io.StringWriter();
            final java.io.PrintWriter pw = new java.io.PrintWriter( sw );
            e.printStackTrace( pw );
            LOG.error( "Exception: " + sw.toString() );
        }
        finally
        {
            if ( needRollback )
            {
                store.rollback( transaction );
            }
        }

    }
847969
public void service(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException
    {
	    boolean fileFound = sendResourceFile(req, resp);
		if (!fileFound)
		    resp.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
//    	super.service(req, resp);
    }
521790
protected void writeContent(String requestedPath, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ResourceNotFoundException {

		// Send gzipped resource if user agent supports it.
		int idx = requestedPath.indexOf(BundleRenderer.GZIP_PATH_PREFIX);
		if (idx != -1) {

			requestedPath = JawrConstant.URL_SEPARATOR
					+ requestedPath.substring(idx + BundleRenderer.GZIP_PATH_PREFIX.length(), requestedPath.length());
			if (isValidRequestedPath(requestedPath)) {
				response.setHeader(CONTENT_ENCODING, GZIP);
				bundlesHandler.streamBundleTo(requestedPath, response.getOutputStream());
			} else {
				throw new ResourceNotFoundException(requestedPath);
			}

		} else {

			// In debug mode, we take in account the image generated from a
			// StreamGenerator like classpath Image generator
			// The following code will rewrite the URL path for the generated
			// images,
			// because in debug mode, we are retrieving the CSS resources
			// directly from the webapp
			// and if the CSS contains generated images, we should rewrite the
			// URL.
			BinaryResourcesHandler imgRsHandler = (BinaryResourcesHandler) servletContext
					.getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE);
			if (imgRsHandler != null && this.jawrConfig.isDebugModeOn() && resourceType.equals(JawrConstant.CSS_TYPE)) {

				handleGeneratedCssInDebugMode(requestedPath, request, response, imgRsHandler);
			} else {

				if (isValidRequestedPath(requestedPath)) {
					Writer out = response.getWriter();
					bundlesHandler.writeBundleTo(requestedPath, out);
				} else {
					throw new ResourceNotFoundException(requestedPath);
				}
			}
		}
	}
885719
public void doPost(HttpServletRequest request,
                        HttpServletResponse response) 
        throws ServletException, IOException
    {
        String target=null;
        response.sendRedirect(request.getContextPath()+
                              request.getServletPath()+"/"+
                              Long.toString(System.currentTimeMillis(),36)+
                              (target!=null?("#"+target):""));
    }