请问renderFile(filename)时何时触发的render方法呢?
我的下载类MyController中代码:
private void renderFile2(String file){ if(FileUtils.fileExist(file)){ File file1 = new File(file); setAttr("rtnFlag", true); renderFile(file1); return; }else{ setAttr("rtnFlag", false); renderText("目前没有反馈表哦!"); } }
Controller类中的源码是:
public void renderFile(File file) { render = renderManager.getRenderFactory().getFileRender(file); }
而RenderFactoryjava中的源码:
public Render getFileRender(File file) { return new FileRender(file); }
那么问题来了何时触发的FileRender.java中的render()方法呢?
public FileRender(File file) { if (file == null) { throw new IllegalArgumentException("file can not be null."); } this.file = file; } ... public void render() { if (file == null || !file.isFile()) { RenderManager.me().getRenderFactory().getErrorRender(404).setContext(request, response).render(); return ; } // --------- response.setHeader("Accept-Ranges", "bytes"); String fn = downloadFileName == null ? file.getName() : downloadFileName; response.setHeader("Content-disposition", "attachment; " + encodeFileName(request, fn)); String contentType = servletContext.getMimeType(file.getName()); response.setContentType(contentType != null ? contentType : DEFAULT_CONTENT_TYPE); // --------- if (StrKit.isBlank(request.getHeader("Range"))) { normalRender(); } else { rangeRender(); } }
项目:JFinal