導航:首頁 > 源碼編譯 > jfinalshop源碼下載

jfinalshop源碼下載

發布時間:2022-01-22 21:00:57

1. 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");
}
}

2. 如何使用python爬蟲jfinal

一、gzip/deflate支持

現在的網頁普遍支持gzip壓縮,這往往可以解決大量傳輸時間,以VeryCD的主頁為例,未壓縮版本247K,壓縮了以後45K,為原來的1/5。這就意味著抓取速度會快5倍。

然而python的urllib/urllib2默認都不支持壓縮,要返回壓縮格式,必須在request的header裡面寫明』accept-encoding』,然後讀取response後更要檢查header查看是否有』content-encoding』一項來判斷是否需要解碼,很繁瑣瑣碎。如何讓urllib2自動支持gzip, defalte呢?

其實可以繼承BaseHanlder類,然後build_opener的方式來處理:

import urllib2from gzip import GzipFilefrom StringIO import StringIOclass ContentEncodingProcessor(urllib2.BaseHandler): """A handler to add gzip capabilities to urllib2 requests """ # add headers to requests def http_request(self, req): req.add_header("Accept-Encoding", "gzip, deflate") return req # decode def http_response(self, req, resp): old_resp = resp # gzip if resp.headers.get("content-encoding") == "gzip": gz = GzipFile( fileobj=StringIO(resp.read()), mode="r" ) resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url, old_resp.code) resp.msg = old_resp.msg # deflate if resp.headers.get("content-encoding") == "deflate": gz = StringIO( deflate(resp.read()) ) resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url, old_resp.code) # 'class to add info() and resp.msg = old_resp.msg return resp # deflate supportimport zlibdef deflate(data): # zlib only provides the zlib compress format, not the deflate format; try: # so on top of all there's this workaround: return zlib.decompress(data, -zlib.MAX_WBITS) except zlib.error: return zlib.decompress(data)

然後就簡單了,

encoding_support = = urllib2.build_opener( encoding_support, urllib2.HTTPHandler ) #直接用opener打開網頁,如果伺服器支持gzip/defalte則自動解壓縮content = opener.open(url).read()

二、更方便地多線程

總結一文的確提及了一個簡單的多線程模板,但是那個東東真正應用到程序裡面去只會讓程序變得支離破碎,不堪入目。在怎麼更方便地進行多線程方面我也動了一番腦筋。先想想怎麼進行多線程調用最方便呢?

1、用twisted進行非同步I/O抓取

事實上更高效的抓取並非一定要用多線程,也可以使用非同步I/O法:直接用twisted的getPage方法,然後分別加上非同步I/O結束時的callback和errback方法即可。例如可以這么干:

from twisted.web.client import getPagefrom twisted.internet import reactor links = [ ''%i for i in range(5420,5430) ] def parse_page(data,url): print len(data),url def fetch_error(error,url): print error.getErrorMessage(),url # 批量抓取鏈接for url in links: getPage(url,timeout=5) \ .addCallback(parse_page,url) \ #成功則調用parse_page方法 .addErrback(fetch_error,url) #失敗則調用fetch_error方法 reactor.callLater(5, reactor.stop) #5秒鍾後通知reactor結束程序reactor.run()

twisted人如其名,寫的代碼實在是太扭曲了,非正常人所能接受,雖然這個簡單的例子看上去還好;每次寫twisted的程序整個人都扭曲了,累得不得了,文檔等於沒有,必須得看源碼才知道怎麼整,唉不提了。

如果要支持gzip/deflate,甚至做一些登陸的擴展,就得為twisted寫個新的HTTPClientFactory類諸如此類,我這眉頭真是大皺,遂放棄。有毅力者請自行嘗試。

這篇講怎麼用twisted來進行批量網址處理的文章不錯,由淺入深,深入淺出,可以一看。

2、設計一個簡單的多線程抓取類

還是覺得在urllib之類python「本土」的東東裡面折騰起來更舒服。試想一下,如果有個Fetcher類,你可以這么調用

f = Fetcher(threads=10) #設定下載線程數為10for url in urls: f.push(url) #把所有url推入下載隊列while f.taskleft(): #若還有未完成下載的線程 content = f.pop() #從下載完成隊列中取出結果 do_with(content) # 處理content內容

這么個多線程調用簡單明了,那麼就這么設計吧,首先要有兩個隊列,用Queue搞定,多線程的基本架構也和「技巧總結」一文類似,push方法和pop方法都比較好處理,都是直接用Queue的方法,taskleft則是如果有「正在運行的任務」或者」隊列中的任務」則為是,也好辦,於是代碼如下:

import urllib2from threading import Thread,Lockfrom Queue import Queueimport time class Fetcher: def __init__(self,threads): self.opener = urllib2.build_opener(urllib2.HTTPHandler) self.lock = Lock() #線程鎖 self.q_req = Queue() #任務隊列 self.q_ans = Queue() #完成隊列 self.threads = threads for i in range(threads): t = Thread(target=self.threadget) t.setDaemon(True) t.start() self.running = 0 def __del__(self): #解構時需等待兩個隊列完成 time.sleep(0.5) self.q_req.join() self.q_ans.join() def taskleft(self): return self.q_req.qsize()+self.q_ans.qsize()+self.running def push(self,req): self.q_req.put(req) def pop(self): return self.q_ans.get() def threadget(self): while True: req = self.q_req.get() with self.lock: #要保證該操作的原子性,進入critical area self.running += 1 try: ans = self.opener.open(req).read() except Exception, what: ans = '' print what self.q_ans.put((req,ans)) with self.lock: self.running -= 1 self.q_req.task_done() time.sleep(0.1) # don't spam if __name__ == "__main__": links = [ ''%i for i in range(5420,5430) ] f = Fetcher(threads=10) for url in links: f.push(url) while f.taskleft(): url,content = f.pop() print url,len(content)

3. 求shop++的源代碼

主要庫
spring-aop-4.0.9.RELEASE
spring-beans-4.0.9.RELEASE
spring-context-4.0.9.RELEASE
spring-context-support-4.0.9.RELEASE
spring-core-4.0.9.RELEASE
spring-expression-4.0.9.RELEASE
spring-jdbc-4.0.9.RELEASE
spring-orm-4.0.9.RELEASE
spring-test-4.0.9.RELEASE
spring-tx-4.0.9.RELEASE
spring-web-4.0.9.RELEASE
spring-webmvc-4.0.9.RELEASE
hibernate-core-4.3.9.Final
hibernate-jpa-2.1-api-1.0.0.Final
hibernate-entitymanager-4.3.9.Final
hibernate-validator-5.1.3.Final
hibernate-search-orm-4.5.3.Final
lucene-core-3.6.2
freemarker-2.3.22
ehcache-core-2.6.10
ehcache-web-2.0.4
shiro-core-1.2.3
shiro-web-1.2.3
c3p0-0.9.2.1
commons-lang-2.6
commons-beanutils-1.9.2
commons-collections-3.2.1
commons-io-2.4
commons-net-3.3
commons-fileupload-1.3.1
commons-codec-1.10
commons-email-1.3.3
commons-compress-1.9
junit-4.10
httpclient-4.3.5
httpcore-4.3.2
slf4j-api-1.7.7
jcl-over-slf4j-1.7.7
logback-core-1.1.2
logback-classic-1.1.2
dom4j-1.6.1
jackson-core-2.4.3
jackson-databind-2.4.3
jackson-annotations-2.4.3
IKAnalyzer2012_u6

4. jfinal2.3的定時任務如何實現

Cron4jPlugin是JFinal集成的任務調度插件,通過使用Cron4jPlugin可以使用通用的cron表達式極為便利的實現任務調度功能。

jfinal2.3我不記得有Cron4jPlugin沒有.
如果沒有 你可以把新版的jfinal更新上來,或者把Cron4jPlugin的源碼拷貝出來放到你的項目中去,可以單獨適用的.

或者直接使用Cron4j就可以,參考:網頁鏈接

5. jfinalshop2.0支持手機瀏覽嗎

使用RedisPlugin 除了需要依賴commons-pool2、jedis這兩個包之外還需要依賴fst 在此附上對應的maven
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.2</version>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency>

<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.31</version>
</dependency>

6. jfinal什麼時候出web版的後台管理

可以加入Jfinal俱樂部,

引用官網的:
俱樂部當前發放的福利是本社區 jfinal.com 的源代碼,並取名為
jfinal-club。jfinal-club 在核心功能上相當於一個迷你的 OSChina 社區,newsfeed
信息流模塊整合了整站動態數據,交互性極好。重要功能:動態消息、@提到我、remind提醒、關注、好友、粉絲、私信、發貼、回貼、點贊、收藏、定時任務等功能。常見的功能也很全面:文件下載、圖片上傳、用戶頭像裁剪、登錄、注冊、郵件激活、找回密碼、XSS過濾、緩存、後台管理、以及一些常用工具類等等。

jfinal-club 是官方出品的唯一 JFinal 最佳實踐,絕無僅有的極簡設計,獲得 jfinal-club 也就獲得了作者本人對
JFinal 的使用精髓。基於 jfinal 3.3 開發,獲得 jfinal-club 將以令人難以想像的速度掌握新版本功能。

jfinal-club 是一個長期進化的,不斷添加實用功能的項目,加入俱樂部以後,將隨之長期享受該福利。

---------------

web版的後台管理社區做的比較好的有:

JfinalUIB , EOVA ,JPress, ... 等很多都非常的好

http://www.jfinal.com/project 相關項目

http://www.jfinal.com/club 俱樂部

7. 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跑起來,然後跑的更快。

8. jfinal上傳大文件 如何斷點續傳

點量Http、FTP多線程斷點續傳下載組件(下載DLL)內核源碼使用高效的c++代碼編寫,提供標準的動態鏈接庫(DLL),可供C/C++、Delphi、C#、Java、VB、PowerBuilder、易語言等語言和各常用開發環境調用。

9. 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");
}
}

10. jfinal+easyui項目源碼

JFinal是一個基於Java的極速Web開發框架,其核心設計目標是開發迅速、代碼量少、學習簡單、功能強大、輕量級、易擴展、Restful。

地址:http://www.csdn.net/tag/jfinal

閱讀全文

與jfinalshop源碼下載相關的資料

熱點內容
伺服器一直崩應該用什麼指令 瀏覽:916
cm202貼片機編程 瀏覽:723
php構造函數帶參數 瀏覽:174
解壓電波歌曲大全 瀏覽:336
為啥文件夾移到桌面成word了 瀏覽:858
命令符的安全模式是哪個鍵 瀏覽:758
編程中學 瀏覽:956
單片機求助 瀏覽:993
ug加工側面排銑毛坯怎麼編程 瀏覽:271
程序員有關的介紹 瀏覽:736
支付寶使用的什麼伺服器 瀏覽:210
安卓看本地書用什麼軟體好 瀏覽:921
經傳軟體滾動凈利潤指標源碼 瀏覽:522
螢石雲視頻已加密怎麼解除 瀏覽:574
一命令四要求五建議 瀏覽:30
qq文件夾遷移不了 瀏覽:19
液體粘滯系數測定不確定度演算法 瀏覽:332
輕棧源碼 瀏覽:426
把圖片壓縮到500k 瀏覽:35
命令你自己 瀏覽:369