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


Java HttpServletResponse.reset方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.reset方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.reset方法的具體用法?Java HttpServletResponse.reset怎麽用?Java HttpServletResponse.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


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

示例1: code

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 生成代碼
 */
@RequestMapping("/code")
@RequiresPermissions("sys:generator:code")
public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{
	String[] tableNames = new String[]{};
	//獲取表名,不進行xss過濾
	HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
	String tables = orgRequest.getParameter("tables");
	tableNames = JSON.parseArray(tables).toArray(tableNames);
	
	byte[] data = sysGeneratorService.generatorCode(tableNames);
	
	response.reset();  
       response.setHeader("Content-Disposition", "attachment; filename=\"renren.zip\"");  
       response.addHeader("Content-Length", "" + data.length);  
       response.setContentType("application/octet-stream; charset=UTF-8");  
 
       IOUtils.write(data, response.getOutputStream());  
}
 
開發者ID:guolf,項目名稱:pds,代碼行數:22,代碼來源:SysGeneratorController.java

示例2: exportExcel

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 導出
 * @param modelName 模型名稱
 * @param excelType excel格式
 * @param response
 * @return
 * @throws IOException
 */
@RequestMapping(value = { "/excel/{modelName}","/excel/{modelName}/{excelType}" }, method = RequestMethod.GET)
public void exportExcel(@PathVariable String modelName,@PathVariable(required = false) String excelType, HttpServletResponse response) throws IOException {
    //默認導出xls格式excel
    if(excelType==null||"".equals(excelType)){
        excelType="XLS";
    }
    List<SysExportModel> models = modelService.queryExportModelByCondition(modelName);
    // 模型不存在 直接結束
    if (models == null || models.size() == 0) {
        return;
    }
    // 獲取導出數據
    SysExportModel model = models.get(0);
    List<List<Object>> exportData = commonService.getAllData(model.getModelName(), model.getEnames(), null);
    List<String> exportHeaderNames = new ArrayList<String>();
    String[] headerNames = model.getCnames().split(",");
    for (String headerName : headerNames) {
        exportHeaderNames.add(headerName);
    }

    response.reset();
    // 文件下載
    response.setContentType("application/vnd.ms-excel");
    String filename = "報表"+modelName+"("+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ ")";

    filename = new String(filename.getBytes("gbk"), "iso-8859-1");
    response.setHeader("Content-disposition", "attachment;filename="+ filename + "."+excelType.toLowerCase());
    response.setBufferSize(1024);

    //獲取excel表單
    ExcelGenerater excelGenerater=new ExcelGenerater();
    ExcelGeneraterBean excelGeneraterBean = excelGenerater.create(modelName, exportHeaderNames, exportData);
    Workbook workbook = excelGeneraterBean.getWorkbook();
    //寫入數據 到流
    workbook.write(response.getOutputStream());
    workbook.close();
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:46,代碼來源:ExportController.java

示例3: handleError

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void handleError(final HttpServletRequest request, final HttpServletResponse response)
		throws IOException {
	// handle limit case, e.g. return status code 429 (Too Many Requests)
	// see http://tools.ietf.org/html/rfc6585#page-3
	final String text = "TOO_MANY_REQUESTS";
	response.reset();
	response.setStatus(429);
	response.setContentType("text/plain");
	response.setCharacterEncoding("US-ASCII");
	response.setContentLength(text.length() + 2);
	response.setHeader("Pragma", "no-cache");
	response.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate");
	final ServletOutputStream out = response.getOutputStream();
	out.println(text);
	out.flush();
	response.flushBuffer();
}
 
開發者ID:ggrandes,項目名稱:concurrentlimit-servlet-filter,代碼行數:18,代碼來源:ConcurrentLimitFilter.java

示例4: DownloadExcelUtil

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 設置文件名和工作表名(Excel)
 * 
 * @param response
 *            為NULL時,寫入磁盤
 * @param fileName
 *            文件名
 * @param sheetName
 *            工作表名
 * @throws IOException
 */
public DownloadExcelUtil(HttpServletResponse response, String fileName, String sheetName) throws IOException {
    startTime = System.currentTimeMillis();
    if (fileName.indexOf(".xls") < 0) {
        fileName += ".xls";
    }
    if (response != null && response instanceof HttpServletResponse) {
        logger.warn("Write Excel To Memory.Please wait...");
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition",
            "attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO8859-1"));

        os = response.getOutputStream();// 獲得輸出流
        os.flush();
        wbook = Workbook.createWorkbook(os); // 創建excel文件
    } else {
        logger.warn("Write Excel To Disk.Please wait...");
        wbook = Workbook.createWorkbook(new File(fileName)); // 創建excel文件
    }
    this.sheetName = sheetName;
    wsheet = wbook.createSheet(sheetName, sheetIndex++); // sheet名稱
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:34,代碼來源:DownloadExcelUtil.java

示例5: DownloadExcelUtil

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 設置文件名和工作表名(Excel)
 * 
 * @param response
 *            為NULL時,寫入磁盤
 * @param fileName
 *            文件名
 * @param sheetName
 *            工作表名
 * @throws IOException
 */
public DownloadExcelUtil(HttpServletResponse response, String fileName, String sheetName)
                                                                                       throws IOException {
    startTime = System.currentTimeMillis();
    if (fileName.indexOf(".xls") < 0) {
        fileName += ".xls";
    }
    if (response != null && response instanceof HttpServletResponse) {
        log.warn("Write Excel To Memory.Please wait...");
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition",
            "attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO8859-1"));

        os = response.getOutputStream();// 獲得輸出流
        os.flush();
        wbook = Workbook.createWorkbook(os); // 創建excel文件
    } else {
        log.warn("Write Excel To Disk.Please wait...");
        wbook = Workbook.createWorkbook(new File(fileName)); // 創建excel文件
    }
    this.sheetName = sheetName;
    wsheet = wbook.createSheet(sheetName, sheetIndex++); // sheet名稱
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:35,代碼來源:DownloadExcelUtil.java

示例6: displayPDF

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void displayPDF() throws IOException {
    HttpServletResponse response = (HttpServletResponse) this.facesContext
            .getExternalContext().getResponse();

    response.reset();
    response.setContentType(this.contentType);
    response.setContentLength(this.content.length);

    response.addHeader("Content-Disposition",
            this.getDisplayType(this.displayType) + "; " + "filename="
                    + this.filename);
    response.addHeader("Accept-Ranges", "bytes");

    BufferedOutputStream outputStream = new BufferedOutputStream(
            response.getOutputStream());
    outputStream.write(this.content);
    outputStream.flush();
    outputStream.close();

    facesContext.responseComplete();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:22,代碼來源:ExternalPriceModelDisplayHandler.java

示例7: exportTemplate

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 導出當前網站當前的模版文件,包含模版頁麵,模版變量、欄目
 * @throws FileNotFoundException
 * @throws UnsupportedEncodingException
 */
@RequestMapping("exportTemplate")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException {
	BaseVO vo = templateService.exportTemplate(request);
	String fileName = "template"+DateUtil.currentDate("yyyyMMdd_HHmm")+".wscso".toString(); // 文件的默認保存名
	//讀到流中
	InputStream inStream = new ByteArrayInputStream(vo.getInfo().getBytes("UTF-8"));  
	
	AliyunLog.addActionLog(getSiteId(), "導出當前網站當前的模版文件");
	
	// 設置輸出的格式
	response.reset();
	response.setContentType("bin");
	response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        // 循環取出流中的數據
	byte[] b = new byte[1000];
	int len;
	try {
	    while ((len = inStream.read(b)) > 0)
	        response.getOutputStream().write(b, 0, len);
	    inStream.close();
	} catch (IOException e) {
	    e.printStackTrace();
	}
}
 
開發者ID:xnx3,項目名稱:wangmarket,代碼行數:30,代碼來源:TemplateController.java

示例8: viewFile

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping("/{codeID}/**")
public void viewFile(@PathVariable("codeID") int codeID,
		HttpServletRequest request,HttpServletResponse res) throws IOException {
	Code code = this.codeService.get(codeID,false);
	String uri = URLDecoder.decode(request.getRequestURI(),"UTF-8");
	String filePath = uri.substring(uri.indexOf("/code/")+6+(""+codeID).length());
	SimpleCode simpleCode = code.getSimpleCode(filePath);

	if (simpleCode == null) {
		res.sendRedirect("http://www.gravatar.com/avatar/a.jpg");
		return;
	}
	byte[] imgData;


	if(WebUtil.isCodeName(filePath))
		imgData = simpleCode.getContent().getBytes("EUC-KR");
	else
		imgData = simpleCode.getContent().getBytes("8859_1");

		res.reset();
		res.setContentType("application/octet-stream");
		String filename = new String(simpleCode.getFileName().getBytes("UTF-8"), "8859_1");
		res.setHeader("Content-Disposition", "attachment; filename = " + filename);

		OutputStream o = res.getOutputStream();
		o.write(imgData);
		o.flush();
		o.close();
		return;

}
 
開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:33,代碼來源:CodeController.java

示例9: download

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping("/{codeID}/{codeName}.zip")
public void download(HttpServletResponse res,
		@PathVariable("codeID") int codeID,
		@PathVariable("codeName") String codeName) throws IOException {
	Code code = this.codeService.get(codeID,false);
	res.reset();
	res.setContentType("application/octet-stream");
	res.setHeader("Content-Disposition", "attachment; filename = " + codeName+".zip");
	res.setContentType(WebUtil.getFileExtension(codeName+".zip"));
	this.codeService.dowloadCode(code, res.getOutputStream());
}
 
開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:12,代碼來源:CodeController.java

示例10: loginForm

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Sends a 401 error to the browser. This forces a login box to be displayed
 * allowing the user to login.
 *
 * @param response
 *        the response to set the headers and status
 */
protected void loginForm(HttpServletResponse response) throws IOException {
    response.reset();
    response.addHeader("WWW-Authenticate",
            "Basic realm=\"!!Fedora Repository Server\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    OutputStream out = response.getOutputStream();
    out.write("Fedora: 401 ".getBytes());
    out.flush();
    out.close();
}
 
開發者ID:discoverygarden,項目名稱:fcrepo3-security-jaas,代碼行數:18,代碼來源:UpstreamAuthFilterJAAS.java

示例11: write

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 輸出到客戶端
 * @param fileName 輸出文件名
 */
public ExportExcel write(HttpServletResponse response, String fileName) throws IOException{
    response.reset();
    response.setContentType("application/octet-stream; charset=utf-8");
    response.setHeader("Content-Disposition", "attachment; filename="+Encodes.urlEncode(fileName));
    write(response.getOutputStream());
    return this;
}
 
開發者ID:sombie007,項目名稱:ExcelHandle,代碼行數:12,代碼來源:ExportExcel.java

示例12: exportFile

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 向客戶端下載文件,彈出下載框.
 *
 * @param response(HttpServletResponse)
 * @param file(需要下載的文件)
 * @param isDel(下載完成後是否刪除該文件)
 * @throws IOException
 */
public static void exportFile(HttpServletResponse response, File file, boolean isDel) throws IOException {
    OutputStream out = null;
    InputStream in = null;

    // 獲得文件名
    String filename = URLEncoder.encode(file.getName(), "UTF-8");
    response.reset();
    // 定義輸出類型(下載)
    response.setContentType("application/x-msdownload");
    response.setHeader("Location", filename);
    // 定義輸出文件頭
    response.setHeader("Content-Disposition", "attachment;filename=" + filename);
    out = response.getOutputStream();
    in = new FileInputStream(file.getPath());

    byte[] buffer = new byte[1024];
    int i = -1;
    while ((i = in.read(buffer)) != -1) {
        out.write(buffer, 0, i);
    }

    in.close();
    out.close();

    if (isDel) {
        //刪除文件,刪除前關閉所有的Stream.
        file.delete();
    }

}
 
開發者ID:tong12580,項目名稱:OutsourcedProject,代碼行數:39,代碼來源:Excel.java

示例13: handle

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@SuppressWarnings("nls")
@Override
public void handle(Throwable exception, SectionInfo info, SectionsController controller, SectionEvent<?> event)
{
	LOGGER.error("Error during ajax request", exception);
	info.setRendered();
	final HttpServletResponse response = info.getResponse();
	if( !response.isCommitted() )
	{
		response.reset();
		response.setStatus(500);
		response.setHeader("Content-Type", "application/json");
		try
		{
			final Map<String, Object> message = new HashMap<String, Object>();
			final Throwable rootCause = Throwables.getRootCause(exception);
			final String errorMessage = Utils.coalesce(rootCause.getMessage(), rootCause.getClass()
				.getCanonicalName());
			message.put("message", errorMessage);
			mapper.writeValue(response.getWriter(), message);
		}
		catch( IOException e )
		{
			throw new SectionsRuntimeException(e);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:28,代碼來源:AjaxExceptionHandler.java

示例14: handleException

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static void handleException(HttpServletResponse response,
        Exception e, String realm, boolean sendBody) throws IOException,
        ServletException {
    if (e instanceof OAuthProblemException) {
        OAuthProblemException problem = (OAuthProblemException) e;
        Object httpCode = problem.getParameters().get(OAuthProblemException.HTTP_STATUS_CODE);
        if (httpCode == null) {
            httpCode = PROBLEM_TO_HTTP_CODE.get(problem.getProblem());
        }
        if (httpCode == null) {
            httpCode = SC_FORBIDDEN;
        }
        response.reset();
        response.setStatus(Integer.parseInt(httpCode.toString()));
        OAuthMessage message = new OAuthMessage(null, null, problem
                .getParameters().entrySet());
        response.addHeader("WWW-Authenticate", message
                .getAuthorizationHeader(realm));
        if (sendBody) {
            sendForm(response, message.getParameters());
        }
    } else if (e instanceof IOException) {
        throw (IOException) e;
    } else if (e instanceof ServletException) {
        throw (ServletException) e;
    } else if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
    } else {
        throw new ServletException(e);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:OAuthServlet.java

示例15: down

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static void down(HttpServletResponse response, InputStream in, String fileName)
		throws Exception {
	fileName = URLEncoder.encode(fileName, "UTF-8");
	response.reset();
	response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
	response.setContentType("application/octet-stream;charset=UTF-8");
	IOUtils.copy(in, response.getOutputStream());
	in.close();
}
 
開發者ID:wu191287278,項目名稱:sc-generator,代碼行數:10,代碼來源:FileUtil.java


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