请教各位~! 如何实现struts下载功能~ 最好把代码贴出来
谢谢~
谢谢~
解决方案 »
- 规则 一个大人和两个小孩可以住一个房间 或者 两个大人和一个小孩可以住一个房间 随便输入一个 大人数和小孩数 求 一共要多少个房间
- 求一个STRUTS2中上传文件到数据库的DEMO(不存储路径,直接存储文件内容到库)
- hibernate映射问题
- JAVA连接Oracle的问题
- 写了个javabean,导入到JSP页面时出错,提示无法解析类.....哪位仁兄帮解决了,我把我在CSDN里所有的分数都送给你
- jsp cookie~
- ssh框架中button传值问题
- Servlet和类存储到数据库中的数据是乱码,这是为什么啊?急啊在线等待
- 已将sql server 2000 for jdbc中的mssqlserver.jar,msbase.jar;msutil.jar放入tomcat 的lib中,并在classpath指定,为什么编译时还是提示
- about servlet
- 动态的改变jsp页面中session中的值
- 谁能提供防止jsp多次提交的各种具体实现方法(包括页面JS)?
String filePath ="文件的路径和文件名字";
resp.reset();//resp==response
if (filePath.endsWith(".doc") || filePath.endsWith(".rtf")) {
resp.setContentType("application/msword");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else if (filePath.endsWith(".pdf")) {
resp.setContentType("application/pdf");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else if (filePath.endsWith(".xls")) {
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-disposition", "inline; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
} else {
resp.setContentType("application/x-msdownload");
resp.setHeader("Content-disposition",
"attachment; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
}
File file = new File(filePath); if(!file.exists())
file = new File(req.getSession().getServletContext().getRealPath("/"+ filePath));
FileInputStream in = org.apache.commons.io.FileUtils
.openInputStream(file);
ServletOutputStream sout = resp.getOutputStream();
int filesize = org.apache.commons.io.IOUtils.copy(in, sout);
sout.close();