當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletOutputStream類代碼示例

本文整理匯總了Java中javax.servlet.ServletOutputStream的典型用法代碼示例。如果您正苦於以下問題:Java ServletOutputStream類的具體用法?Java ServletOutputStream怎麽用?Java ServletOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServletOutputStream類屬於javax.servlet包,在下文中一共展示了ServletOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verify

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
/**
 * 生成驗證碼的邏輯
 */
@RequestMapping("verify")
private ModelAndView verify(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession();
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");
    String capText = captchaProducer.createText();
    session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
    BufferedImage bi = captchaProducer.createImage(capText);
    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(bi, "jpg", out);
    try {
        out.flush();
    } finally {
        out.close();
    }
    return null;
}
 
開發者ID:cx118118,項目名稱:ssm-rbac,代碼行數:24,代碼來源:PublicController.java

示例2: getOutputStream

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@Override
public ServletOutputStream getOutputStream() throws IOException {

  final ServletOutputStream outputStream = d.getOutputStream();
  return new ServletOutputStream() {

    @Override
    public void write(int b) throws IOException {
      respBody.write(b);
      outputStream.write(b);
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {
      outputStream.setWriteListener(writeListener);
    }

    @Override
    public boolean isReady() {
      return outputStream.isReady();
    }
  };
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:24,代碼來源:AccessLogFilter.java

示例3: writeToResponse

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
/**
 * Write the given temporary OutputStream to the HTTP response.
 * @param response current HTTP response
 * @param baos the temporary OutputStream to write
 * @throws IOException if writing/flushing failed
 */
protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException {
    // Write content type and also length (determined via byte array).
    response.setContentType(getContentType());
    response.setContentLength(baos.size());

    // Flush byte array to servlet output stream.
    ServletOutputStream out = response.getOutputStream();
    baos.writeTo(out);
    out.flush();
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:17,代碼來源:AbstractView.java

示例4: updateResponse

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
private void updateResponse(String requestURI, ContentCachingResponseWrapper responseWrapper) throws IOException {
	try {
		HttpServletResponse rawResponse = (HttpServletResponse) responseWrapper.getResponse();
		byte[] body = responseWrapper.getContentAsByteArray();
		ServletOutputStream outputStream = rawResponse.getOutputStream();
		if (rawResponse.isCommitted()) {
			if (body.length > 0) {
				StreamUtils.copy(body, outputStream);
			}
		} else {
			if (body.length > 0) {
				rawResponse.setContentLength(body.length);
				StreamUtils.copy(body, rawResponse.getOutputStream());
			}
		}
		finishResponse(outputStream, body);
	} catch (Exception ex) {
		logger.error("請求地址為" + requestURI + "的連接返回報文失敗,原因是{}", ex.getMessage());
	}
}
 
開發者ID:wengwh,項目名稱:plumdo-stock,代碼行數:21,代碼來源:RequestLogFilter.java

示例5: exportExcel

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
/**
    * Exports tool results into excel.
    * 
    * @throws IOException
    */
   private ActionForward exportExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException {

initializeScratchieService();
String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
Scratchie scratchie = (Scratchie) sessionMap.get(ScratchieConstants.ATTR_SCRATCHIE);

LinkedHashMap<String, ExcelCell[][]> dataToExport = service.exportExcel(scratchie.getContentId());

String fileName = "scratchie_export.xlsx";
fileName = FileUtil.encodeFilenameForDownload(request, fileName);

response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);

// set cookie that will tell JS script that export has been finished
String downloadTokenValue = WebUtil.readStrParam(request, "downloadTokenValue");
Cookie fileDownloadTokenCookie = new Cookie("fileDownloadToken", downloadTokenValue);
fileDownloadTokenCookie.setPath("/");
response.addCookie(fileDownloadTokenCookie);

// Code to generate file and write file contents to response
ServletOutputStream out = response.getOutputStream();
ExcelUtil.createExcel(out, dataToExport, null, false);

return null;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:MonitoringAction.java

示例6: captcha

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response) throws ServletException, IOException {
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setContentType("image/jpeg");

    //生成文字驗證碼
    String text = producer.createText();
    //生成圖片驗證碼
    BufferedImage image = producer.createImage(text);
    //保存到shiro session
    ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);

    ServletOutputStream out = response.getOutputStream();
    ImageIO.write(image, "jpg", out);
    IOUtils.closeQuietly(out);


}
 
開發者ID:davichi11,項目名稱:my-spring-boot-project,代碼行數:19,代碼來源:SysLoginController.java

示例7: exportReservationsCsv

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@RequestMapping(value = Mappings.ADMINISTRATION_EXPORT_RESERVATIONS_CSV, method = RequestMethod.GET)
public void exportReservationsCsv(
        @RequestParam("begin") String begin,
        @RequestParam("end") String end,
        HttpServletResponse response) throws Exception {

    Date beginDate = Utils.stringToDate(begin);
    Date endDate = Utils.stringToDate(end);

    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment; filename=\"export.csv\"");

    File tempFile = exportService.exportReserationsCsv(beginDate, endDate);

    try (ServletOutputStream out = response.getOutputStream();
         InputStream in = Files.newInputStream(tempFile.toPath())) {
        IOUtils.copy(in, out);
    }

    Files.delete(tempFile.toPath());

}
 
開發者ID:remipassmoilesel,項目名稱:simple-hostel-management,代碼行數:23,代碼來源:AdministrationController.java

示例8: writeResponse

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@SuppressWarnings("deprecation")
protected void writeResponse(Response res) throws Exception {
    response.setStatus(res.getStatusCode(), res.getStatusMessage());
    for (HeaderField header : res.getHeader().getAllHeaderFields()) {
        if (header.getHeaderName().equals(Header.TRANSFER_ENCODING))
            continue;
        response.addHeader(header.getHeaderName().toString(), header.getValue());
    }

    ServletOutputStream out = response.getOutputStream();
    res.getBody().write(new PlainBodyTransferrer(out));
    out.flush();

    response.flushBuffer();

    exchange.setTimeResSent(System.currentTimeMillis());
    exchange.collectStatistics();
}
 
開發者ID:membrane,項目名稱:membrane-spring-boot-starter,代碼行數:19,代碼來源:HttpServletHandler.java

示例9: copyRange

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param istream The input stream to read from
 * @param ostream The output stream to write to
 * @return Exception which occurred during processing
 */
private IOException copyRange(InputStream istream,
                              ServletOutputStream ostream) {

    // Copy the input stream to the output stream
    IOException exception = null;
    byte buffer[] = new byte[input];
    int len = buffer.length;
    while (true) {
        try {
            len = istream.read(buffer);
            if (len == -1)
                break;
            ostream.write(buffer, 0, len);
        } catch (IOException e) {
            exception = e;
            len = -1;
            break;
        }
    }
    return exception;

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:32,代碼來源:DefaultServlet.java

示例10: captcha

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
	response.setHeader("Cache-Control", "no-store, no-cache");
	response.setContentType("image/jpeg");

	//生成文字驗證碼
	String text = producer.createText();
	//生成圖片驗證碼
	BufferedImage image = producer.createImage(text);
	//保存到shiro session
	ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);

	ServletOutputStream out = response.getOutputStream();
	ImageIO.write(image, "jpg", out);
	IOUtils.closeQuietly(out);
}
 
開發者ID:zhaoqicheng,項目名稱:renren-fast,代碼行數:17,代碼來源:SysLoginController.java

示例11: getAttachmentContent

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@RequestMapping(value = "/email/attachment/{id}",method = RequestMethod.GET)
public void getAttachmentContent(@PathVariable("id") Long id, HttpServletResponse response) {

	final AttachmentEntity attachment = attachmentService.findAttachmentById(id);

	if (attachment != null) {
		try {
			ServletOutputStream stream = response.getOutputStream();
			OutputStream out = new BufferedOutputStream(stream);

			response.resetBuffer();
			response.setBufferSize(attachment.getAttachmentContent().getData().length);
			response.setHeader("Content-Length", String.valueOf(attachment.
                       getAttachmentContent().getData().length));

			out.write(attachment.getAttachmentContent().getData());

			out.close();
			stream.close();
		} catch (final IOException e) {
			log.error("Unable to open file", e);
		}
	} else {
		log.error("File does not exist");
	}
}
 
開發者ID:dopse,項目名稱:maildump,代碼行數:27,代碼來源:EmailController.java

示例12: startJob

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@RequestMapping(value="/launchjob")
@ResponseBody
public void startJob(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {

    log.info("manual startJob");
    try {
        httpServletResponse.setContentType("text/plain; charset=utf-8");
        ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
        if(scheduleJobs.getJobStatus() == ScheduleJobs.JOB_STATUS_RUNNING) {
            responseOutputStream.write("Job正在運行。。。".getBytes("utf-8"));
            responseOutputStream.flush();
            responseOutputStream.close();
        } else {
            log.info("scheduleJobs.cronJob() start by controller...");
            scheduleJobs.cronJob();
        }
    } catch (Exception e) {
        log.info("startJob exception e="+e.getMessage());
    }
}
 
開發者ID:fengzhizi715,項目名稱:ProxyPool,代碼行數:21,代碼來源:CommonController.java

示例13: doPost

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	req.setCharacterEncoding("utf-8");
	resp.setCharacterEncoding("utf-8");
	HashMap<String, Object> status = new HashMap<>();
	JSONObject object = new JSONObject();
	String quizFormName = req.getParameter("name");
	// get main data
	QuizForm qf = allQuizForm.get(quizFormName);
	// build status
	status.put("code", String.valueOf(HttpServletResponse.SC_OK));
	status.put("message", "query quiz form successful");
	status.put("extra", Constant.JSON.EMPTY_OBJECT);
	status.put("security", Constant.JSON.EMPTY_OBJECT);
	// build main object
	object.put("meta", status);
	object.put("data", qf);
	// FIXME 非測試時移去注釋 (配合Configuration System把這裏設計的合理一點 - 磷)
	// response.setContentType("application/json"); // specific content type
	try (ServletOutputStream out = resp.getOutputStream()) {
		out.write(resp.toString().getBytes(StandardCharsets.UTF_8));
		out.flush();
	} catch (IOException e) {
		LoggerFactory.getLogger(Counter.class).error("IOException thrown: ", e);
	}
}
 
開發者ID:ProgramLeague,項目名稱:strictfp-back-end,代碼行數:27,代碼來源:GetQuiz.java

示例14: generate

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
/**
 * 生成驗證碼
 */
static void generate(HttpServletResponse response, String vCode) {
	BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
	response.setHeader("Pragma","no-cache");
	response.setHeader("Cache-Control","no-cache");
	response.setDateHeader("Expires", 0);
	response.setContentType("image/jpeg");
	
	ServletOutputStream sos = null;
	try {
		drawGraphic(image, vCode);
		sos = response.getOutputStream();
		ImageIO.write(image, "JPEG", sos);
		sos.flush();
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		IOUtils.closeQuietly(sos);
	}
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:23,代碼來源:CaptchaUtils.java

示例15: doService

import javax.servlet.ServletOutputStream; //導入依賴的package包/類
private void doService(HttpMethod method, HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    outputRequestLog(req);

    InputStream iStream = null;
    ServletOutputStream oStream = null;
    try {
        long threadID = Thread.currentThread().getId();
        log.debug("[" + threadID + "] forwarded to " + distributer.getRedirectUrl(req));
        HttpClient client = new HttpClient();
        log.debug("[" + threadID + "]send request.");
        int resultCode = client.executeMethod(method);
        log.debug("[" + threadID + "]got response: result code is " + resultCode);
        res.setStatus(resultCode);
        for (Header header : method.getResponseHeaders()) {
            res.setHeader(header.getName(), header.getValue());
        }
        iStream = method.getResponseBodyAsStream();
        oStream = res.getOutputStream();

        writeOutputStream(iStream, oStream);

        log.debug("[" + threadID + "] response sent to client.");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    } finally {
        if (iStream != null) {
            iStream.close();
        }
        if (oStream != null) {
            oStream.close();
        }
    }
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:36,代碼來源:ForwarderServlet.java


注:本文中的javax.servlet.ServletOutputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。