struts2 动态文件下载 (在javaeye里搜索过,没找到满意的)
诚心请教
struts2 文件下载,我想把一个文件下的文件全部显示在页面上,
每个文件后有个下载链接,点击“下载”,就可以下载到硬盘上了,struts.xml,
Filedownload.java ,我只会写到这了。
如果大家有空就帮我看看,谢谢!
还要解决中文问题!!!
请会的人帮帮我,非常感谢!我已经做了好长时间了
在其他论坛帖了好几天了,只有看的,没回复的,加了
10几个java高级群也是这样因此帖到javaeye,希望大家能够帮忙!
在外面学,没有老师,只能通过这些方式了!
struts.xml
?
Filedownload.java
import java.io.InputStream;import java.io.UnsupportedEncodingException;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class Filedownload extends ActionSupport { // 下载文件原始存放路径 private final static String DOWNLOADFILEPATH = "/file/"; // 文件名参数变量 private String fileName; public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } // 从下载文件原始存放路径读取得到文件输出流 public InputStream getDownloadFile() { return ServletActionContext.getServletContext().getResourceAsStream(DOWNLOADFILEPATH + fileName); //这里的filename写成固定的文件名如aa.txt这样就是写死了,只能下载一个,我想filename是一个集合 //里面有很多文件可供下载 } // 如果下载文件名为中文,进行字符编码转换 public String getDownloadChineseFileName() { String downloadChineseFileName = fileName; try { downloadChineseFileName = new String(downloadChineseFileName .getBytes(), "ISO8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return downloadChineseFileName; } public String execute() { return SUCCESS; }}?
?