package Demo;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class downFile extends ActionSupport{
public String list() throws Exception {
String path = ServletActionContext.getServletContext().getRealPath("/upload");
File file = new File(path);
String[] fileNames = file.list();
ActionContext ac = ActionContext.getContext();
Map<String, Object> request = (Map<String, Object>) ac.get("request");
request.put("fileNames", fileNames);
return "list";
}
private String fileName;
public void setFileName(String fileName) {
try {
fileName = new String(fileName.getBytes("ISO8859-1"),"utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.fileName = fileName;
}
public InputStream getAttrInputStream(){
return ServletActionContext.getServletContext().getResourceAsStream("/upload/"+fileName);
}
public String getDownFileName(){
try {
fileName = URLEncoder.encode(fileName,"utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fileName;
}
public String down(){
return "down";
}
}
最近下载更多
最近浏览更多
PSSDZH LV3
2024年6月14日
LARY LV1
2024年1月5日
WBelong LV8
2023年12月19日
uni-code_0123 LV1
2023年12月7日
abcd20231129
2023年11月27日
暂无贡献等级
xmx123 LV5
2023年9月14日
小屁孩 LV7
2023年6月2日
Super强 LV13
2023年6月2日
微信网友_6326642137403392
2023年1月29日
暂无贡献等级
sweetlove LV20
2022年11月28日

