<action name="download" method="fileLoad" class="com.gnet.todometters.fileDownloadAction">
<result name="success" type="stream">
<param name="contentType">application/octet-stream;charset=utf-8</param>
<param name="contentDisposition">attachment;filename="${nfileName}"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
action:
public class FileDownloadAction extends BaseAction{
private String nfileName;
public InputStream getDownloadFile() throws Exception {
HttpServletRequest request=ServletActionContext.getRequest();
String folder = ServletActionContext.getServletContext().getRealPath("/upFile");
String realPath=folder+"\\"+nfileName;
return new FileInputStream(new File(realPath));
// return ServletActionContext.getServletContext().getResourceAsStream(realPath);
} // 如果下载文件名为中文,进行字符编码转换
public String getDownloadChineseFileName() throws UnsupportedEncodingException {
String downloadChineseFileName = nfileName; try {
downloadChineseFileName = new String(downloadChineseFileName
.getBytes(), "gbk");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} return downloadChineseFileName;
} public String fileLoad(){
return SUCCESS;
} public String getNfileName() {
String downloadChineseFileName = nfileName; try {
downloadChineseFileName = new String(downloadChineseFileName
.getBytes(), "iso8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} return downloadChineseFileName;
} public void setNfileName(String nfileName) {
this.nfileName = nfileName;
}
错误我看过了,值没有从配置文件传到action中,不知道为什么,急求,谢谢....
<result name="success" type="stream">
<param name="contentType">application/octet-stream;charset=utf-8</param>
<param name="contentDisposition">attachment;filename="${nfileName}"</param>
<param name="inputName">downloadFile</param>
</result>
</action>
action:
public class FileDownloadAction extends BaseAction{
private String nfileName;
public InputStream getDownloadFile() throws Exception {
HttpServletRequest request=ServletActionContext.getRequest();
String folder = ServletActionContext.getServletContext().getRealPath("/upFile");
String realPath=folder+"\\"+nfileName;
return new FileInputStream(new File(realPath));
// return ServletActionContext.getServletContext().getResourceAsStream(realPath);
} // 如果下载文件名为中文,进行字符编码转换
public String getDownloadChineseFileName() throws UnsupportedEncodingException {
String downloadChineseFileName = nfileName; try {
downloadChineseFileName = new String(downloadChineseFileName
.getBytes(), "gbk");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} return downloadChineseFileName;
} public String fileLoad(){
return SUCCESS;
} public String getNfileName() {
String downloadChineseFileName = nfileName; try {
downloadChineseFileName = new String(downloadChineseFileName
.getBytes(), "iso8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} return downloadChineseFileName;
} public void setNfileName(String nfileName) {
this.nfileName = nfileName;
}
错误我看过了,值没有从配置文件传到action中,不知道为什么,急求,谢谢....
解决方案 »
- CXF2.0.10的问题.100分
- 如何获取forEach里的每个值
- 菜鸟提问1
- 关于servlet.getDebug()的问题,请大家帮忙解决!
- org.xml.sax.SAXParseException: Document is invalid: no grammar found
- struts2标签遍历Map<Course,String>类型
- 真的是很头痛的问题,问题也不知道在哪里,求助各位老师了
- 如何修改Tomcat5的jsp文件放置路径?
- 你开发所用的操作系统、计算机配置调查
- 出现如下配置entity bean时错误,请大家帮小弟一下,我刚自学jbuilder和weblogic
- 怎么自动辨别用户ip是电信,网通或是移动铁通及其他
- 关于面试的问题
HttpServletRequest request=ServletActionContext.getRequest();
String folder = ServletActionContext.getServletContext().getRealPath("/upFile");
String realPath=folder+"\\"+nfileName;
downloadFile = new FileInputStream(new File(realPath));
return downloadFile
// return ServletActionContext.getServletContext().getResourceAsStream(realPath);
}
public String download() throws Exception {
try {
String filePath = servletRequest.getParameter("filePath");
File file = new File(filePath);
String fileName = file.getName().replaceAll("\\[.+\\]", "");
fileName = URLEncoder.encode(fileName, "utf-8");
fileName = fileName.replace('+', ' ');
servletResponse.setContentType("application/x-download");
servletResponse.addHeader("Content-Disposition",
"attachment;filename=" + fileName); excelStream = new FileInputStream(file);
}
catch(Exception e) {
write(Tool.getErrorMsg(e.getMessage())); return ERROR;
} return SUCCESS;
}
<action name="search_export"
class="com.xxx.hdm.servlet.Search" method="export">
<result name="success" type="stream">
<param name="inputName">excelStream</param>
</result>
<result name="error">search_detail.jsp</result>
</action>