当前位置:首页 » 操作系统 » jfinal源码下载

jfinal源码下载

发布时间: 2023-01-31 10:37:24

‘壹’ jfinal 如何导出zip压缩文件

官网介绍:JFinal 是基于 java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、pythonphp等动态语言的开发效率!为您节约更多时间,去陪恋人、家人和朋友 :)

Jfinal做为后台,进行下载文件服务时,源码中可看到:

Controller中已经提供了,方法:

/**
*Renderwithfile
*/
publicvoidrenderFile(StringfileName){
render=renderManager.getRenderFactory().getFileRender(fileName);
}

/**
*Renderwithfile,
*/
publicvoidrenderFile(StringfileName,StringdownloadFileName){
render=renderManager.getRenderFactory().getFileRender(fileName,downloadFileName);
}

/**
*Renderwithfile
*/
publicvoidrenderFile(Filefile){
render=renderManager.getRenderFactory().getFileRender(file);
}

/**
*Renderwithfile,
file=文件,downloadFileName=下载时客户端显示的文件名称,很贴心
*/
publicvoidrenderFile(Filefile,StringdownloadFileName){
render=renderManager.getRenderFactory().getFileRender(file,downloadFileName);
}

大家可以看到源码中 FileRender 是有处理各个浏览器的兼容问题,所以可以方便的使用

/**
*Copyright(c)2011-2017,JamesZhan詹波([email protected]).
*
*LicensendertheApacheLicense,Version2.0(the"License");
*.
*YoumayobtainaoftheLicenseat
*
*http://www.apache.org/licenses/LICENSE-2.0
*
*,software
*"ASIS"BASIS,
*,eitherexpressorimplied.
*
*limitationsundertheLicense.
*/

packagecom.jfinal.render;

importjava.io.BufferedInputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.io.UnsupportedEncodingException;
importjava.net.URLEncoder;
importjavax.servlet.ServletContext;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importcom.jfinal.kit.LogKit;
importcom.jfinal.kit.StrKit;

/**
*FileRender.
*/
{

_CONTENT_TYPE="application/octet-stream";
;
;

protectedFilefile;
=null;

publicFileRender(Filefile){
if(file==null){
("filecannotbenull.");
}
this.file=file;
}

publicFileRender(Filefile,StringdownloadFileName){
this(file);

if(StrKit.isBlank(downloadFileName)){
("downloadFileNamecannotbeblank.");
}
this.downloadFileName=downloadFileName;
}

publicFileRender(StringfileName){
if(StrKit.isBlank(fileName)){
("fileNamecannotbeblank.");
}

StringfullFileName;
fileName=fileName.trim();
if(fileName.startsWith("/")||fileName.startsWith("\")){
if(baseDownloadPath.equals("/")){
fullFileName=fileName;
}else{
fullFileName=baseDownloadPath+fileName;
}
}else{
fullFileName=baseDownloadPath+File.separator+fileName;
}

this.file=newFile(fullFileName);
}

publicFileRender(StringfileName,StringdownloadFileName){
this(fileName);

if(StrKit.isBlank(downloadFileName)){
("downloadFileNamecannotbeblank.");
}
this.downloadFileName=downloadFileName;
}

staticvoidinit(StringbaseDownloadPath,ServletContextservletContext){
FileRender.baseDownloadPath=baseDownloadPath;
FileRender.servletContext=servletContext;
}

publicvoidrender(){
if(file==null||!file.isFile()){
RenderManager.me().getRenderFactory().getErrorRender(404).setContext(request,response).render();
return;
}

//---------
response.setHeader("Accept-Ranges","bytes");
Stringfn=downloadFileName==null?file.getName():downloadFileName;
response.setHeader("Content-disposition","attachment;"+encodeFileName(request,fn));
StringcontentType=servletContext.getMimeType(file.getName());
response.setContentType(contentType!=null?contentType:DEFAULT_CONTENT_TYPE);

//---------
if(StrKit.isBlank(request.getHeader("Range"))){
normalRender();
}else{
rangeRender();
}
}

protectedStringencodeFileName(StringfileName){
try{
//returnnewString(fileName.getBytes("GBK"),"ISO8859-1");
returnnewString(fileName.getBytes(getEncoding()),"ISO8859-1");
}catch(UnsupportedEncodingExceptione){
returnfileName;
}
}

/**
*依据浏览器判断编码规则
*/
publicStringencodeFileName(HttpServletRequestrequest,StringfileName){
StringuserAgent=request.getHeader("User-Agent");
try{
StringencodedFileName=URLEncoder.encode(fileName,"UTF8");
//如果没有UA,则默认使用IE的方式进行编码
if(userAgent==null){
return"filename=""+encodedFileName+""";
}

userAgent=userAgent.toLowerCase();
//IE浏览器,只能采用URLEncoder编码
if(userAgent.indexOf("msie")!=-1){
return"filename=""+encodedFileName+""";
}

//Opera浏览器只能采用filename*
if(userAgent.indexOf("opera")!=-1){
return"filename*=UTF-8''"+encodedFileName;
}

//Safari浏览器,只能采用ISO编码的中文输出,Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出
if(userAgent.indexOf("safari")!=-1||userAgent.indexOf("applewebkit")!=-1||userAgent.indexOf("chrome")!=-1){
return"filename=""+newString(fileName.getBytes("UTF-8"),"ISO8859-1")+""";
}

//FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出
if(userAgent.indexOf("mozilla")!=-1){
return"filename*=UTF-8''"+encodedFileName;
}

return"filename=""+encodedFileName+""";
}catch(UnsupportedEncodingExceptione){
thrownewRuntimeException(e);
}
}

protectedvoidnormalRender(){
response.setHeader("Content-Length",String.valueOf(file.length()));
InputStreaminputStream=null;
OutputStreamoutputStream=null;
try{
inputStream=newBufferedInputStream(newFileInputStream(file));
outputStream=response.getOutputStream();
byte[]buffer=newbyte[1024];
for(intlen=-1;(len=inputStream.read(buffer))!=-1;){
outputStream.write(buffer,0,len);
}
outputStream.flush();
outputStream.close();
}catch(IOExceptione){
Stringn=e.getClass().getSimpleName();
if(n.equals("ClientAbortException")||n.equals("EofException")){
}else{
thrownewRenderException(e);
}
}catch(Exceptione){
thrownewRenderException(e);
}finally{
if(inputStream!=null)
try{inputStream.close();}catch(IOExceptione){LogKit.error(e.getMessage(),e);}
}
}

protectedvoidrangeRender(){
Long[]range={null,null};
processRange(range);

StringcontentLength=String.valueOf(range[1].longValue()-range[0].longValue()+1);
response.setHeader("Content-Length",contentLength);
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);//status=206

//Content-Range:bytes0-499/10000
StringBuildercontentRange=newStringBuilder("bytes").append(String.valueOf(range[0])).append("-").append(String.valueOf(range[1])).append("/").append(String.valueOf(file.length()));
response.setHeader("Content-Range",contentRange.toString());

InputStreaminputStream=null;
OutputStreamoutputStream=null;
try{
longstart=range[0];
longend=range[1];
inputStream=newBufferedInputStream(newFileInputStream(file));
if(inputStream.skip(start)!=start)
thrownewRuntimeException("Fileskiperror");
outputStream=response.getOutputStream();
byte[]buffer=newbyte[1024];
longposition=start;
for(intlen;position<=end&&(len=inputStream.read(buffer))!=-1;){
if(position+len<=end){
outputStream.write(buffer,0,len);
position+=len;
}
else{
for(inti=0;i<len&&position<=end;i++){
outputStream.write(buffer[i]);
position++;
}
}
}
outputStream.flush();
outputStream.close();
}
catch(IOExceptione){
Stringn=e.getClass().getSimpleName();
if(n.equals("ClientAbortException")||n.equals("EofException")){
}else{
thrownewRenderException(e);
}
}
catch(Exceptione){
thrownewRenderException(e);
}
finally{
if(inputStream!=null)
try{inputStream.close();}catch(IOExceptione){LogKit.error(e.getMessage(),e);}
}
}

/**
*Examplesofbyte-ranges-specifiervalues(assuminganentity-bodyoflength10000):
*Thefirst500bytes(byteoffsets0-499,inclusive):bytes=0-499
*Thesecond500bytes(byteoffsets500-999,inclusive):bytes=500-999
*Thefinal500bytes(byteoffsets9500-9999,inclusive):bytes=-500
*Orbytes=9500-
*/
protectedvoidprocessRange(Long[]range){
StringrangeStr=request.getHeader("Range");
intindex=rangeStr.indexOf(',');
if(index!=-1)
rangeStr=rangeStr.substring(0,index);
rangeStr=rangeStr.replace("bytes=","");

String[]arr=rangeStr.split("-",2);
if(arr.length<2)
thrownewRuntimeException("Rangeerror");

longfileLength=file.length();
for(inti=0;i<range.length;i++){
if(StrKit.notBlank(arr[i])){
range[i]=Long.parseLong(arr[i].trim());
if(range[i]>=fileLength)
range[i]=fileLength-1;
}
}

//Rangeformatlike:9500-
if(range[0]!=null&&range[1]==null){
range[1]=fileLength-1;
}
//Rangeformatlike:-500
elseif(range[0]==null&&range[1]!=null){
range[0]=fileLength-range[1];
range[1]=fileLength-1;
}

//checkfinalrange
if(range[0]==null||range[1]==null||range[0].longValue()>range[1].longValue())
thrownewRuntimeException("Rangeerror");
}
}

‘贰’ 现在JFinal越来越火,它的发展趋势怎么样

JFinal 采用微内核全方位扩展架构,全方位是指其扩展方式在空间上的表现形式。JFinal由Handler、Interceptor、Controller、Render、Plugin五大部分组成。

看过源码的都知道, JFinal 是轻薄封装, 原理还是javax.servlet.http.HttpServletRequest等, 所以学好原理, 是最靠谱的, JFinal是为我们快速开发业务实现用的, 新手最好先学会javax.servlet 再来上手JFinal ,
发展趋势 ? 当做一个工具就好了, Java项目都可以放入JFinal , 小巧方便的, 招聘JFinal 也挺多的

‘叁’ JFinal 集成kisso怎么使用里面的shiro

这个你需要看kisso的代码了。

推荐一套完整的Shiro Demo,免费的。

推荐一套完整的ShiroDemo,免费的。
ShiroDemo:http://www.sojson.com/shiro
Demo已经部署到线上,地址是http://shiro.itboy.net

管理员帐号:admin,密码:sojson.com如果密码错误,请用sojson。PS:你可以注册自己的帐号,然后用管理员赋权限给你自己的帐号,但是,每20分钟会把数据初始化一次。建议自己下载源码,让Demo跑起来,然后跑的更快。


管理员帐号:admin,密码:sojson.com 如果密码错误,请用sojson。PS:你可以注册自己的帐号,然后用管理员赋权限给你自己的帐号,但是,每20分钟会把数据初始化一次。建议自己下载源码,让Demo跑起来,然后跑的更快。

‘肆’ jfinal不兼容的浏览器有哪些

官网介绍:
JFinal 是基于 Java 语言的极速 WEB + ORM
框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python、php等动态语言的开发效率!为您节约更多时间,去陪恋人、家人和朋友
:)

Jfinal是JAVA框架, 不在浏览器上执行的, 是两个方向。
如果你说的是Jfinal做为后台,进行下载文件服务时,是否有浏览器兼容问题,在Jfinal3.0之后的版已经全面兼容了

3.3版的源码中可看到已经有处理:

/**
*Copyright(c)2011-2017,JamesZhan詹波([email protected]).
*
*LicensendertheApacheLicense,Version2.0(the"License");
*.
*YoumayobtainaoftheLicenseat
*
*http://www.apache.org/licenses/LICENSE-2.0
*
*,software
*"ASIS"BASIS,
*,eitherexpressorimplied.
*
*limitationsundertheLicense.
*/

packagecom.jfinal.render;

importjava.io.BufferedInputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
importjava.io.UnsupportedEncodingException;
importjava.net.URLEncoder;
importjavax.servlet.ServletContext;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importcom.jfinal.kit.LogKit;
importcom.jfinal.kit.StrKit;

/**
*FileRender.
*/
{

_CONTENT_TYPE="application/octet-stream";
;
;

protectedFilefile;
=null;

publicFileRender(Filefile){
if(file==null){
("filecannotbenull.");
}
this.file=file;
}

publicFileRender(Filefile,StringdownloadFileName){
this(file);

if(StrKit.isBlank(downloadFileName)){
("downloadFileNamecannotbeblank.");
}
this.downloadFileName=downloadFileName;
}

publicFileRender(StringfileName){
if(StrKit.isBlank(fileName)){
("fileNamecannotbeblank.");
}

StringfullFileName;
fileName=fileName.trim();
if(fileName.startsWith("/")||fileName.startsWith("\")){
if(baseDownloadPath.equals("/")){
fullFileName=fileName;
}else{
fullFileName=baseDownloadPath+fileName;
}
}else{
fullFileName=baseDownloadPath+File.separator+fileName;
}

this.file=newFile(fullFileName);
}

publicFileRender(StringfileName,StringdownloadFileName){
this(fileName);

if(StrKit.isBlank(downloadFileName)){
("downloadFileNamecannotbeblank.");
}
this.downloadFileName=downloadFileName;
}

staticvoidinit(StringbaseDownloadPath,ServletContextservletContext){
FileRender.baseDownloadPath=baseDownloadPath;
FileRender.servletContext=servletContext;
}

publicvoidrender(){
if(file==null||!file.isFile()){
RenderManager.me().getRenderFactory().getErrorRender(404).setContext(request,response).render();
return;
}

//---------
response.setHeader("Accept-Ranges","bytes");
Stringfn=downloadFileName==null?file.getName():downloadFileName;
response.setHeader("Content-disposition","attachment;"+encodeFileName(request,fn));
StringcontentType=servletContext.getMimeType(file.getName());
response.setContentType(contentType!=null?contentType:DEFAULT_CONTENT_TYPE);

//---------
if(StrKit.isBlank(request.getHeader("Range"))){
normalRender();
}else{
rangeRender();
}
}

protectedStringencodeFileName(StringfileName){
try{
//returnnewString(fileName.getBytes("GBK"),"ISO8859-1");
returnnewString(fileName.getBytes(getEncoding()),"ISO8859-1");
}catch(UnsupportedEncodingExceptione){
returnfileName;
}
}

/**
*依据浏览器判断编码规则
*/
publicStringencodeFileName(HttpServletRequestrequest,StringfileName){
StringuserAgent=request.getHeader("User-Agent");
try{
StringencodedFileName=URLEncoder.encode(fileName,"UTF8");
//如果没有UA,则默认使用IE的方式进行编码
if(userAgent==null){
return"filename=""+encodedFileName+""";
}

userAgent=userAgent.toLowerCase();
//IE浏览器,只能采用URLEncoder编码
if(userAgent.indexOf("msie")!=-1){
return"filename=""+encodedFileName+""";
}

//Opera浏览器只能采用filename*
if(userAgent.indexOf("opera")!=-1){
return"filename*=UTF-8''"+encodedFileName;
}

//Safari浏览器,只能采用ISO编码的中文输出,Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出
if(userAgent.indexOf("safari")!=-1||userAgent.indexOf("applewebkit")!=-1||userAgent.indexOf("chrome")!=-1){
return"filename=""+newString(fileName.getBytes("UTF-8"),"ISO8859-1")+""";
}

//FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出
if(userAgent.indexOf("mozilla")!=-1){
return"filename*=UTF-8''"+encodedFileName;
}

return"filename=""+encodedFileName+""";
}catch(UnsupportedEncodingExceptione){
thrownewRuntimeException(e);
}
}

protectedvoidnormalRender(){
response.setHeader("Content-Length",String.valueOf(file.length()));
InputStreaminputStream=null;
OutputStreamoutputStream=null;
try{
inputStream=newBufferedInputStream(newFileInputStream(file));
outputStream=response.getOutputStream();
byte[]buffer=newbyte[1024];
for(intlen=-1;(len=inputStream.read(buffer))!=-1;){
outputStream.write(buffer,0,len);
}
outputStream.flush();
outputStream.close();
}catch(IOExceptione){
Stringn=e.getClass().getSimpleName();
if(n.equals("ClientAbortException")||n.equals("EofException")){
}else{
thrownewRenderException(e);
}
}catch(Exceptione){
thrownewRenderException(e);
}finally{
if(inputStream!=null)
try{inputStream.close();}catch(IOExceptione){LogKit.error(e.getMessage(),e);}
}
}

protectedvoidrangeRender(){
Long[]range={null,null};
processRange(range);

StringcontentLength=String.valueOf(range[1].longValue()-range[0].longValue()+1);
response.setHeader("Content-Length",contentLength);
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);//status=206

//Content-Range:bytes0-499/10000
StringBuildercontentRange=newStringBuilder("bytes").append(String.valueOf(range[0])).append("-").append(String.valueOf(range[1])).append("/").append(String.valueOf(file.length()));
response.setHeader("Content-Range",contentRange.toString());

InputStreaminputStream=null;
OutputStreamoutputStream=null;
try{
longstart=range[0];
longend=range[1];
inputStream=newBufferedInputStream(newFileInputStream(file));
if(inputStream.skip(start)!=start)
thrownewRuntimeException("Fileskiperror");
outputStream=response.getOutputStream();
byte[]buffer=newbyte[1024];
longposition=start;
for(intlen;position<=end&&(len=inputStream.read(buffer))!=-1;){
if(position+len<=end){
outputStream.write(buffer,0,len);
position+=len;
}
else{
for(inti=0;i<len&&position<=end;i++){
outputStream.write(buffer[i]);
position++;
}
}
}
outputStream.flush();
outputStream.close();
}
catch(IOExceptione){
Stringn=e.getClass().getSimpleName();
if(n.equals("ClientAbortException")||n.equals("EofException")){
}else{
thrownewRenderException(e);
}
}
catch(Exceptione){
thrownewRenderException(e);
}
finally{
if(inputStream!=null)
try{inputStream.close();}catch(IOExceptione){LogKit.error(e.getMessage(),e);}
}
}

/**
*Examplesofbyte-ranges-specifiervalues(assuminganentity-bodyoflength10000):
*Thefirst500bytes(byteoffsets0-499,inclusive):bytes=0-499
*Thesecond500bytes(byteoffsets500-999,inclusive):bytes=500-999
*Thefinal500bytes(byteoffsets9500-9999,inclusive):bytes=-500
*Orbytes=9500-
*/
protectedvoidprocessRange(Long[]range){
StringrangeStr=request.getHeader("Range");
intindex=rangeStr.indexOf(',');
if(index!=-1)
rangeStr=rangeStr.substring(0,index);
rangeStr=rangeStr.replace("bytes=","");

String[]arr=rangeStr.split("-",2);
if(arr.length<2)
thrownewRuntimeException("Rangeerror");

longfileLength=file.length();
for(inti=0;i<range.length;i++){
if(StrKit.notBlank(arr[i])){
range[i]=Long.parseLong(arr[i].trim());
if(range[i]>=fileLength)
range[i]=fileLength-1;
}
}

//Rangeformatlike:9500-
if(range[0]!=null&&range[1]==null){
range[1]=fileLength-1;
}
//Rangeformatlike:-500
elseif(range[0]==null&&range[1]!=null){
range[0]=fileLength-range[1];
range[1]=fileLength-1;
}

//checkfinalrange
if(range[0]==null||range[1]==null||range[0].longValue()>range[1].longValue())
thrownewRuntimeException("Rangeerror");
}
}

‘伍’ 如何评价Jfinal,Jpress

首先,我是从qbasic开始编程,经历了qb到vb,vb到asp(不带.net),asp到jsp,jsp到php,再回头学习j2ee。这个过程可能导致我的观点可能跟主流观点不同,希望各位理解。

j2ee并不等于spring struts hibernate,还有各种其他的选择,ssh不是唯一甚至不是最好的选择,这里按下不表。

先问一个问题,什么是jsp/servlet不能做,而ssh能做的?没有ssh之前,就没有web应用了么?

有人会觉得servlet傻,可是你看看struts的核心入口Dispatcher,不就是一个Servlet么。你觉得jdbc难用,hibernate的功能最后还是用jdbc实现的,而且不少批量处理的情况,还是原生sql好用,以至于hibernate不得不提供原生sql接口,mybatis正是从这里挖走不少用户。

在很多情况下,ssh做的,只不过是把java/jsp/servlet/jdbc本来就具有的功能,封装成不一样的API,把原先用Java编写的代码变成用XML编写,然后在用java写的解释器在jvm里面去运行这些XML。所以,我觉得ssh其实就是面向web开发这个领域创造出来的一组DSL(领域特定语言)。而这套语言以XML开始,现在转移到java的注解annotation,慢慢的又回归java语言本身。

不太全面的说,struts就是给不熟悉html/css/js的web程序员摆脱它们写业务逻辑用的,hibernate就是给不熟悉SQL的程序员摆脱SQL写数据库程序用的,spring就是给不熟悉java的接口、反射的程序员摆脱接口反射写AOP用的。而上面被代替的这些,恰恰是相关领域的原生DSL,这里面多少有一点讽刺的意味,对么?

如果struts的开发者没有在jsp混杂java片段的各种<%="'"+xx.yy()+"'"%>嵌套括号引号海里面摸爬滚打过来,你觉得他们会想到要做struts么?
如果hibernate的开发者没有在SQL的join链中绕晕过,他们会搞hibernate?
如果spring的开发者没有对java反射的异常数量吐过槽,会有spring?

如果你只想做一个平庸的码农,去学ssh能让你找到一份不错的入门工作。
如果你希望能深入的理解系统、语言、框架,去学习语言本身提供的功能,去学习servlet、jdbc、java,去看看如何用他们构造通用的复杂的系统,也许未来5-10年,人们再提起j2ee,说的就是你创造的框架的名字,而不再是什么spring struts hibernate。

我们总是希望高内聚低耦合,但两者通常是矛盾的;如果你愿意放弃其中的一个,就可以在另一个上面走的更远。

‘陆’ jfinal .findById 与.find谁的效率高

findById :是按照主键查询,肯定只能查询一条或者0条记录,一般数据库默认主键为索引,使用索引速度肯定快的
find:按照你的sql语句的where条件查询,查询0-N条。
按照你的需求,如果要按照主键查询建议用findById,如果查询多条只能用find。
如果要查询1条记录,硬是要比较速度,还是findById比较快,看源码find要进行很多list的实例化。

热点内容
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:166
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:736
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:148
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:399
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:544
access数据库exe 发布:2025-05-12 12:39:04 浏览:632
五开的配置是什么 发布:2025-05-12 12:36:37 浏览:366