中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Struts2 多文件上傳

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

1、建一個上傳頁面multiUpload.jsp


<body>
    <h4>this is the fileupload2.jsp for many file</h4>
    <form action="fileupload" method="post" enctype="multipart/form-data">
    	username : <input type="text" name="username" ><br>
    	file1 : <input type="file" name="file"><br>
    	file2 : <input type="file" name="file"><br>
    	file3 : <input type="file" name="file"><br>
    	<input type="submit" value="submit"><br> 
    </form>
  </body>


2、寫對應(yīng)的action處理類:

public class UpLoad2Action extends ActionSupport {

	private String username;
	private List<File> file;
	private List<String> fileFileName;
	private List<String> fileContentType;
	

	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public List<File> getFile() {
		return file;
	}

	public void setFile(List<File> file) {
		this.file = file;
	}
	public List<String> getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(List<String> fileFileName) {
		this.fileFileName = fileFileName;
	}
	public List<String> getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(List<String> fileContentType) {
		this.fileContentType = fileContentType;
	}

	@Override
	public String execute() throws Exception {
		for (int i = 0; i < file.size(); i++) {
			InputStream is = new FileInputStream(file.get(i));
			String root = ServletActionContext.getRequest().getRealPath("/upload");
			File dest = new File(root, fileFileName.get(i));
			OutputStream os = new FileOutputStream(dest);
			byte[] buffer = new byte[1024];
			int len = 0;
			while ((len = is.read(buffer)) != -1) {
				os.write(buffer, 0, len);
			}
			is.close();
			os.close();
		}
		return SUCCESS;
	}
}

3、配置struts.xml文件:

<action name="fileupload" class="com.strong.action.UpLoad2Action">
			<result name="success">/present2.jsp</result>
		</action>


4、顯示頁面:

<body>
    <h4>this is the fileUploadResult2.jsp</h4>
     username : <s:property value="username"/><br>
     <!-- 迭代去取上傳文件的名字 ,-->
     <s:iterator value="fileFileName" id="f">
    	 fileName: <s:property value="#f"/><br>
     </s:iterator>
  </body>


標簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:TextView實現(xiàn)跑馬燈效果

下一篇:Android子線程更新UI兩種方法