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

熱點內容
python發郵件腳本 發布:2025-05-05 22:39:05 瀏覽:280
我的世界伺服器怎麼獲取音樂 發布:2025-05-05 22:23:32 瀏覽:98
win7資料庫 發布:2025-05-05 22:19:04 瀏覽:197
微信在哪裡改支付的手勢密碼 發布:2025-05-05 22:14:15 瀏覽:819
鎖加密 發布:2025-05-05 22:11:52 瀏覽:269
sql創建唯一索引 發布:2025-05-05 22:07:09 瀏覽:191
五菱榮光v多功能存儲 發布:2025-05-05 21:58:27 瀏覽:285
如何用自己電腦建伺服器外網可以 發布:2025-05-05 21:56:04 瀏覽:529
如何解開別人手機密碼 發布:2025-05-05 21:39:09 瀏覽:193
關於漢服課程的視頻腳本 發布:2025-05-05 21:33:30 瀏覽:734