<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
jsp页面
package com.moretv.update.action;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class IndexAction extends ActionSupport { private Listfiles;//更新文件集合 private List filesFileName;//files的文件名集合 private List filesContentType;//files文件的類型集合public String index() {if (files != null) { for (int i = 0; i < files.size(); i++) { InputStream is; OutputStream os; try { //每个升级文件的文件名 String fName = "D:\\"+filesFileName.get(i); is = new java.io.FileInputStream(files.get(i)); os = new java.io.FileOutputStream(fName); byte buffer[] = new byte[8192]; int count = 0; while ((count = is.read(buffer)) > 0) { os.write(buffer, 0, count); } os.close(); is.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }return "SUCCESS"; } public List getFilesFileName() { return filesFileName; } public void setFilesFileName(List filesFileName) { this.filesFileName = filesFileName; } public List getFilesContentType() { return filesContentType; } public void setFilesContentType(List filesContentType) { this.filesContentType = filesContentType; } public void setFiles(List files) { this.files = files; } public List
action代码
==============================
在某些情况下可能发生,jar包没有问题,代码没有问题,但是却无法获取页面传来文件,这有可能是缺少了文件上传拦截器的缘故。例子如下:
/A/list.action