當前位置:首頁 » 文件管理 » 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-02 09:32:15 瀏覽:144
危化品停車場消防器材如何配置 發布:2025-07-02 09:31:37 瀏覽:812
為什麼蘋果連安卓的熱點用這么快 發布:2025-07-02 09:31:30 瀏覽:87
easyui顯示資料庫數據 發布:2025-07-02 09:30:51 瀏覽:237
櫻花計劃腳本 發布:2025-07-02 09:30:50 瀏覽:867
計算機多層存儲系統的主要組成 發布:2025-07-02 09:26:25 瀏覽:541
同等配置的聯想和戴爾哪個更好 發布:2025-07-02 09:02:33 瀏覽:125
華為如何查詢以前設置過的密碼 發布:2025-07-02 09:02:28 瀏覽:183
c語言地圖 發布:2025-07-02 09:00:14 瀏覽:490
計算機的主存儲器是指軟盤的容量 發布:2025-07-02 08:53:49 瀏覽:238