当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.getOutputStream方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletResponse.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.getOutputStream方法的具体用法?Java HttpServletResponse.getOutputStream怎么用?Java HttpServletResponse.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.getOutputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verify

import javax.servlet.http.HttpServletResponse; //导入方法依赖的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: writeToResponse

import javax.servlet.http.HttpServletResponse; //导入方法依赖的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

示例3: exportExcel

import javax.servlet.http.HttpServletResponse; //导入方法依赖的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

示例4: api

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(AdminBiz.MAPPING)
@PermessionLimit(limit=false)
public void api(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // invoke
    RpcResponse rpcResponse = doInvoke(request);

    // serialize response
    byte[] responseBytes = HessianSerializer.serialize(rpcResponse);

    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    //baseRequest.setHandled(true);

    OutputStream out = response.getOutputStream();
    out.write(responseBytes);
    out.flush();
}
 
开发者ID:mmwhd,项目名称:stage-job,代码行数:19,代码来源:JobApiController.java

示例5: processRequest

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/zip");
    
     // This should send the file to browser
     OutputStream out = response.getOutputStream();
     File my_file = new File(absoluteFileName);
     FileInputStream in = new FileInputStream(my_file);
     byte[] buffer = new byte[4096];
     int length;
     while ((length = in.read(buffer)) > 0){
        out.write(buffer, 0, length);
     }
     in.close();
     out.flush();
}
 
开发者ID:lupino22,项目名称:kronometer,代码行数:26,代码来源:DownloadTemplate.java

示例6: render

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public Object render(ActionRequest actionRequest) throws IOException {
    HttpServletResponse response = actionRequest.response;
    if (etag != null) {
        response.setHeader("Etag", etag);
    }
    ServletUtil.prepareResponse(response, downloadFileName, mimeType, length);

    InputStream contentInputStream = this.inputStream;
    OutputStream out = response.getOutputStream();

    StreamUtil.copy(contentInputStream, out);

    out.flush();

    StreamUtil.close(contentInputStream);
    return null;
}
 
开发者ID:febit,项目名称:febit,代码行数:19,代码来源:RawResult.java

示例7: doGet

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	
	String token = AuthConfig.getToken();
	Long user_id=AuthConfig.getUser_id();
	OutputStream os = resp.getOutputStream();
	
	if (token!=null&&user_id>0) {
		Map<String, String> data = new HashMap<String, String>();
		data.put("token", token);
		data.put("user_id", user_id.toString());
		
		String returnAnswer = HttpRequest.post(authUrl).form(data).body();
		os.write(returnAnswer.getBytes("UTF-8"));
		
	}
	os.flush();
	os.close();
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:21,代码来源:GetAllTextsServlet.java

示例8: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
	// RPC调用
       RpcResponse rpcResponse = doInvoke(request);

       // 序列化响应结果
       byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
	
	response.setContentType("text/html;charset=utf-8");
	response.setStatus(HttpServletResponse.SC_OK);
	baseRequest.setHandled(true);
	
	OutputStream out = response.getOutputStream();
	out.write(responseBytes);
	out.flush();
	
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:18,代码来源:JettyServerHandler.java

示例9: getCsv

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "/exportCsvFile/{stats}", method = RequestMethod.GET)
public void getCsv(@PathVariable("stats") String stats, HttpServletRequest request, HttpServletResponse response, Locale locale) throws UnsupportedEncodingException, IOException {
	
	response.setContentType("text/csv");
	String reportName = "editable.csv";
	response.setHeader("Set-Cookie", "fileDownload=true; path=/");
	response.setHeader("Content-disposition", "attachment;filename=" + reportName);
	
	final String[] header = exportService.getHeader(stats);
	
	Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
	
	ICsvBeanWriter beanWriter =  new CsvBeanWriter(writer, CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);

	beanWriter.writeHeader(header);
	
	try{
		List<ExportBean>  objs = exportService.getBean(stats, locale);
		for(ExportBean item : objs) {
			beanWriter.write(item, header);
		}
		beanWriter.flush();
		
		writer.close();
		
	}catch(Exception e){
		log.error("interruption de l'export !",e);
	} finally {
           if( beanWriter != null ) {
               beanWriter.close();
           }
	}
		
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:35,代码来源:ImportExportController.java

示例10: sendAvailableSeries

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private void sendAvailableSeries ( final HttpServletRequest request, final HttpServletResponse response, final String itemId ) throws IOException, ServletException
{
    setHeaders ( request, response );
    final PrintWriter pw = new PrintWriter ( response.getOutputStream () );
    try
    {
        pw.println ( Utils.gson.toJson ( this.exporter.get ().getSeries ( itemId ) ) );
    }
    catch ( final Exception e )
    {
        throw new ServletException ( e );
    }
    pw.close ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:JsonServlet.java

示例11: renderMergedOutputModel

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    byte[] bytes = JSON.toJSONString(filterModel(model), this.serializerFeatures).getBytes(this.charset);
    OutputStream stream = this.updateContentLength ? createTemporaryOutputStream() : response.getOutputStream();
    stream.write(bytes);
    if (this.updateContentLength) {
        writeToResponse(response, (ByteArrayOutputStream) stream);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:FastJsonJsonView.java

示例12: writeObjectToJson

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:17,代码来源:WriteJsonServletHandler.java

示例13: doService

import javax.servlet.http.HttpServletResponse; //导入方法依赖的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

示例14: exportWebpageJSONByDomain

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * 根据domain导出 webpage的JSON对象
 *
 * @param domain     domain
 * @param includeRaw 是否包含网页快照
 */
@RequestMapping(value = "exportWebpageJSONByDomain", method = RequestMethod.GET, produces = "application/octet-stream")
public void exportWebpageJSONByDomain(String domain,
                                      @RequestParam(value = "includeRaw", required = false, defaultValue = "false") Boolean includeRaw,
                                      HttpServletResponse response) throws IOException {
    response.setCharacterEncoding("utf-8");
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
    response.setHeader("Content-Disposition", "attachment;fileName=" + new String(domain.getBytes("UTF-8"), "iso-8859-1") + ".segtxt");
    OutputStream outputStream = response.getOutputStream();
    webpageService.exportWebpageJSONByDomain(domain, includeRaw, outputStream);
    outputStream.close();
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:18,代码来源:CommonWebpageController.java

示例15: pcap

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "/api/session/pcap", method = RequestMethod.POST)
public void pcap(@Valid @RequestBody SipSessionRequest request,
                 HttpServletResponse response) throws Exception {
    response.setContentType("application/vnd.tcpdump.pcapOutputStream");
    response.setHeader("Content-Disposition", "attachment; filename=\"Tapir" + String.join("-", request.getCallIds() + ".pcapOutputStream\""));
    try (
            ByteArrayOutputStream os = session.pcap(request);
            ServletOutputStream sos = response.getOutputStream()
    ) {
        os.writeTo(sos);
    }
}
 
开发者ID:sip3io,项目名称:tapir,代码行数:13,代码来源:SipSessionController.java


注:本文中的javax.servlet.http.HttpServletResponse.getOutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。