问题
Hi Guys i am a beginner in java. I am currently working in apache wicket which is a java based framework. I am trying to create a load button to select and upload multiple files in a particular folder. I already have this piece of code using which i am able to select and upload a single file but i am confused doing same selecting and uploading multiple files.
Thanks in advance
public class HomePage extends WebPage {
private FileUploadField fileUpload;
private String UPLOAD_FOLDER = "C:\\";
public HomePage(final PageParameters parameters) {
add(new FeedbackPanel("feedback"));
Form<?> form = new Form<Void>("form") {
@Override
protected void onSubmit() {
final FileUpload uploadedFile = fileUpload.getFileUpload();
if (uploadedFile != null) {
//write to a new file
File newFile = new File(UPLOAD_FOLDER
+ uploadedFile.getClientFileName());
if (newFile.exists()) {
newFile.delete();
}
try {
newFile.createNewFile();
uploadedFile.writeTo(newFile);
///file which is diplayed after uploading
info("" + uploadedFile.getClientFileName());
}
catch (Exception e)
{
throw new IllegalStateException("Error");
}
}
}
};
// Enable multipart mode (need for uploads file)
form.setMultiPart(true);
// max upload size, 10k
form.setMaxSize(Bytes.kilobytes(1000));
form.add(fileUpload = new FileUploadField("fileUpload"));
add(form);
}
}
回答1:
Yes, there is MultiFileUploadField
, but note that it allows you to select some files only one by one. (open dialog->choose file->press 'open'->open dialog->choose file...). Working example here. Click "source code" link to see...source code.
There is also HTML5 solution, which allows you to select multiple files at once. Here it is, the last one. Note that it won't work in html version < 5.
And no, you can't fetch parent folder path, because of security issue. (it's not about wicket, this is about web development).
来源:https://stackoverflow.com/questions/26230170/how-to-allow-user-to-select-and-upload-multiple-file-in-a-prticular-folder-and-g