當前位置:首頁 » 文件管理 » 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;
}
//的代碼不需要很復雜,簡單的執行資料庫插入就好。

熱點內容
大呼腳本 發布:2025-07-03 07:01:43 瀏覽:504
魅族安卓7和安卓8什麼區別 發布:2025-07-03 06:57:36 瀏覽:59
編譯國外的報紙 發布:2025-07-03 06:54:26 瀏覽:826
oss編程 發布:2025-07-03 06:53:06 瀏覽:966
apache解析php7 發布:2025-07-03 06:47:34 瀏覽:894
壓縮mdb資料庫 發布:2025-07-03 06:47:30 瀏覽:352
王思聰當年30萬的電腦是什麼配置 發布:2025-07-03 06:47:27 瀏覽:631
androidndk的使用 發布:2025-07-03 06:41:45 瀏覽:344
網路音頻上傳 發布:2025-07-03 06:41:03 瀏覽:652
腳本真牛批 發布:2025-07-03 06:36:09 瀏覽:883