當前位置:首頁 » 文件管理 » 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-09-16 09:25:46 瀏覽:598
用中文編譯的編程軟體 發布:2025-09-16 09:04:37 瀏覽:142
語音編譯器教程 發布:2025-09-16 08:57:44 瀏覽:447
sql注冊伺服器 發布:2025-09-16 08:53:17 瀏覽:610
嵌入式linuxc編程入門 發布:2025-09-16 08:24:18 瀏覽:382
碼片編程器 發布:2025-09-16 08:24:08 瀏覽:951
原神各畫質要什麼配置 發布:2025-09-16 08:17:32 瀏覽:320
讀取資料庫生成xml 發布:2025-09-16 08:17:19 瀏覽:797
sql2000開發版 發布:2025-09-16 07:56:31 瀏覽:807
linux桌面哪個 發布:2025-09-16 07:55:35 瀏覽:60