當前位置:首頁 » 文件管理 » ssh2上傳圖片

ssh2上傳圖片

發布時間: 2024-02-09 08:54:16

① 如何上傳本地文件到Linux伺服器

上傳本地文件到Linux伺服器的方法如下:

  1. 在網路下載一個FXP文件上傳工具

② SSH2框架圖片上傳到資料庫並顯示在JSP頁面

java">//傳統的struts2上傳是很簡單的。
//頁面form提交到action:

//這里使用集合,頁面提交過來的n個inputname=「file」的文件將會被裝進去,如果只上傳一
//個文件可以直接聲明成:privateFilefile、StringfileFileName、StringfileContentType
privateList<File>file;
privateList<String>fileFileName;
privateList<String>fileContentType;
publicList<File>getFile(){
returnfile;
}
publicvoidsetFile(List<File>file){
this.file=file;
}
publicList<String>getFileFileName(){
returnfileFileName;
}
publicvoidsetFileFileName(List<String>fileFileName){
this.fileFileName=fileFileName;
}
publicList<String>getFileContentType(){
returnfileContentType;
}
publicvoidsetFileContentType(List<String>fileContentType){
this.fileContentType=fileContentType;
}
publicStringexecute()throwsException{
List<String>s=newArrayList<String>();
for(inti=0;i<file.size();i++){

InputStreamis=newFileInputStream(file.get(i));

//在webroot先建立個upload文件夾,也可以用代碼創建,這里為了簡便,就直接使用了
Stringroot=ServletActionContext.getRequest().getRealPath("/upload");

FiledistFile=newFile(root,this.getFileFileName().get(i));

OutputStreamos=newFileOutputStream(distFile);

byte[]buffer=newbyte[400];

intlength=0;

while((length=is.read(buffer))>0){
os.write(buffer,0,length);
}

is.close();
os.close();

//資料庫存放以下路徑,當需要在頁面顯示,直接提取出來用IMG標簽裝載即可
StringnewFilePath=root+"/"+distFile.getFileName();
}
returnSUCCESS;
}
//的代碼不需要很復雜,簡單的執行資料庫插入就好。

熱點內容
java直播網站源碼 發布:2025-07-04 14:46:35 瀏覽:169
安卓應用市場消費記錄怎麼刪除 發布:2025-07-04 14:39:47 瀏覽:30
知道一個伺服器的ip地址 發布:2025-07-04 14:20:33 瀏覽:597
蘋果7鎖屏密碼怎麼改 發布:2025-07-04 14:04:44 瀏覽:710
P三零是什麼配置 發布:2025-07-04 13:58:41 瀏覽:361
哪個安卓機有長方形home鍵 發布:2025-07-04 13:43:58 瀏覽:861
android腳本錄制 發布:2025-07-04 13:17:47 瀏覽:342
嵌入式和安卓哪個硬體成本高 發布:2025-07-04 13:05:56 瀏覽:229
360代理伺服器怎麼設置 發布:2025-07-04 12:49:49 瀏覽:515
iphone在哪清除緩存 發布:2025-07-04 12:49:38 瀏覽:340