[b]一下是我页面下载链接和java类及配置文件,英文文件名迅雷和windows下载均正常,中文时迅雷得到的文件名是乱码,而且下载不了,用Windows右击目标另存为,报错63485 ERROR 2010-06-04 21:18:08304
org.apache.struts2.dispatcher.StreamResult Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the tag specified for this action,然后点击取消报错,[/b]
package com.office.struts;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.apache.struts2.ServletActionContext;
import com.juyan.struts2.httpservlet.SrrFactory;
import com.office.dao.FileTreeDao;
import com.opensymphony.xwork2.ActionSupport;
public class DownLoadAction extends ActionSupport {
/**
* 文件下载类
*/
private static final long serialVersionUID = 1L;
FileTreeDao fileTreeDao;
String pt;
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getContentDisposition() {
return contentDisposition;
}
public void setContentDisposition(String contentDisposition) {
this.contentDisposition = contentDisposition;
}
private String contentType;
private String contentDisposition;
public FileTreeDao getFileTreeDao() {
return fileTreeDao;
}
public void setFileTreeDao(FileTreeDao fileTreeDao) {
this.fileTreeDao = fileTreeDao;
}
String fileName;
public String getFileName() throws UnsupportedEncodingException {
fileName=new String(fileName.getBytes(),"ISO-8859-1");
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public InputStream getInputStream() {
File file = new File(pt);
try {
InputStream inputStream=new FileInputStream(file);
return inputStream;
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}
public String execute() {
System.out.println(SrrFactory.getHttpServletRequestObject().getParameter(
"fileName"));
System.out.println(SrrFactory.getHttpServletRequestObject()
.getParameter("filePath")
+ "\\"
+ SrrFactory.getHttpServletRequestObject().getParameter(
"fileName"));
this.pt = SrrFactory.getHttpServletRequestObject().getParameter(
"filePath")
+ "\\"
+ SrrFactory.getHttpServletRequestObject().getParameter(
"fileName");
return "success";
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
application/octet-stream;charset=ISO8859-1
inputStream
attachment;filename="${fileName}"
4096