我正在使用Struts 2构建一个应用程序。我在这里有一个部分,我给用户一个选项来上传他们想要的任何pdf文件。这将存储在我在G驱动器中创建的文件夹中。现在我想添加一个选项,用户可以在其中查看目录中存在的文件列表,也可以查看或删除它。 我已经添加了一个帮助查看列表的jsp。
package net.admin.module;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadAction extends ActionSupport{
private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
private String destPath;
public String getFileUploadContentType() {
return fileUploadContentType;
}
public void setFileUploadContentType(String fileUploadContentType) {
this.fileUploadContentType = fileUploadContentType;
}
public String getFileUploadFileName() {
return fileUploadFileName;
}
public void setFileUploadFileName(String fileUploadFileName) {
this.fileUploadFileName = fileUploadFileName;
}
public File getFileUpload() {
return fileUpload;
}
public void setFileUpload(File fileUpload) {
this.fileUpload = fileUpload;
}
public String execute()
{
String targetPath = "G:/FileUploadAction/";
File fileToCreate = new File(targetPath, fileUploadFileName);
try
{
FileUtils.copyFile(this.fileUpload, fileToCreate);
}
catch (IOException e)
{
addActionError(e.getMessage());
}
return SUCCESS;
}
public String display() {
return NONE;
}
}
这是我的动作类
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*" errorPage="" %>
<%!
public static List recurseDir(String dir) {
String result, _result[];
result = recurseInDirFrom(dir);
_result = result.split("\\|");
return Arrays.asList(_result);
}
private static String recurseInDirFrom(String dirItem) {
File file;
String list[], result;
result = dirItem;
file = new File(dirItem);
if (file.isDirectory()) {
list = file.list();
for (int i = 0; i < list.length; i++)
result = result + "|" + recurseInDirFrom(dirItem + File.separatorChar + list[i]);
}
return result;
}
%>
<%
String path = "G:/FileUploadAction/";
List sd=recurseDir(path);
for(int i=0;i<sd.size();i++)
{
out.println(i+" "+sd.get(i)+"<br>");
}
%>
<%
File f=new File("G:/FileUploadAction/Holiday List.pdf");
f.delete();
%>
这是我的jsp,它列出了已存在的文件。
我如何继续查看并删除它?