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

struts圖片上傳實例

發布時間: 2023-05-25 20:08:44

㈠ 怎麼用struts2實現多圖片上傳

新建Web Project,在WebRoot下新建upload文件夾
在WebRoot下新建upload.jsp,上傳界面

編寫上傳成功、失敗的提示界面。
在WebRoot下新建uploadError.jsp

在WebRoot下新建 uploadSuccess.jsp

編寫Action類

配置struts.xml文件,重置fileUpload攔截器。

測試,測試完成之後在tomcat下面webapps目錄下找到項目對應的文件夾下的upload下查看

㈡ struts上傳多張圖片怎麼做,要求可以說上傳中文的,而且圖片可以重復上傳不被覆蓋

你指的是一次上傳多張嗎?我這有個自己寫的例子:
//上傳實體類
public class Upload {
private File photoes; //封裝上傳文件的屬性
private String photoesFileName; //封裝上傳文件的名稱屬性
private String photoesContentType; //封裝上傳文件的類型屬性
private String targetdir; //保存路徑
private String targetfilename; //保存的文件名

public File getPhotoes() {
return photoes;
}
public void setPhotoes(File photoes) {
this.photoes = photoes;
}
public String getPhotoesFileName() {
return photoesFileName;
}
public void setPhotoesFileName(String photoesFileName) {
this.photoesFileName = photoesFileName;
}
public String getPhotoesContentType() {
return photoesContentType;
}
public void setPhotoesContentType(String photoesContentType) {
this.photoesContentType = photoesContentType;
}
public String getTargetdir() {
return targetdir;
}
public void setTargetdir(String targetdir) {
this.targetdir = targetdir;
}
public String getTargetfilename() {
return targetfilename;
}
public void setTargetfilename(String targetfilename) {
this.targetfilename = targetfilename;
}
}
這是上傳圖片的Action類中的部分代碼
//獲得伺服器上保存上傳文件的目錄images的絕對路徑
String realpath = ServletActionContext.getServletContext().getRealPath("/images");
//設置保存文件的目錄
uld.setTargetdir(realpath);
//設置目標文件名
uld.setTargetfilename(generateFileName(uld.getPhotoesFileName()));
//把doc內容復制到target
FileUtils.File(uld.getPhotoes(), new File(uld.getTargetdir(),uld.getTargetfilename()));

㈢ struts2上傳圖片

可以直接在上傳的時候就創建一個tomcat下的目錄吧 圖片都放裡面

㈣ 在Struts2中如何上傳圖片並將剛剛上傳的圖片立即顯示出來

//action的關鍵代碼
import com.xt.gyz.facelook.service.FacesService;
public class ShowPic extends ActionSupport {

private InputStream is;
private Integer id;
private FacesService facesService;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public void setFacesService(FacesService facesService) {
this.facesService = facesService;
}

public InputStream getIs() {
return is;
}

public void setIs(InputStream is) {
this.is = is;
}

@Override
public String execute() throws Exception {
Faces face=facesService.findById(id);
is=new ByteArrayInputStream(face.getPic());
// FileOutputStream fos=new FileOutputStream(new File("E:/body.jpg"));
//頃返 System.out.println(fos);
// System.out.println("face:"+face.getPic().length);
//圓乎消 fos.write(face.getPic());
// fos.flush();
// fos.close();
return super.execute();
}
}
//不要忘記struts.xml配置
......
<action name="showPic" class="showPicAction">
<result type="stream">
<param name="inputName">is</param>
<param name="contectType">image/jpg</橘知param>
</result>
</action>
.....

這樣就可以啦

熱點內容
sift演算法詳解 發布:2025-02-08 18:35:23 瀏覽:578
linux標准錯誤的是 發布:2025-02-08 18:32:07 瀏覽:915
蠻多小說怎麼緩存書架的小說 發布:2025-02-08 18:30:16 瀏覽:888
光遇花開腳本封號嗎 發布:2025-02-08 18:23:15 瀏覽:534
怎麼弄ld帳號和密碼 發布:2025-02-08 18:11:42 瀏覽:628
新逍客20發動機壓縮比 發布:2025-02-08 17:58:10 瀏覽:115
qq號和密碼我都知道為什麼登不上 發布:2025-02-08 17:52:21 瀏覽:872
寶塔伺服器ip進不去 發布:2025-02-08 17:52:18 瀏覽:382
擔保中介源碼 發布:2025-02-08 17:14:37 瀏覽:413
手機存儲卡速度測試 發布:2025-02-08 17:02:57 瀏覽:26