`
hbing110
  • 浏览: 87169 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

webwork 文件下载

    博客分类:
  • java
阅读更多
webwork做文件下载:
首先在xwork.xml中添加以下内容
<action name="download" class="com.mycompany.action.FileDownloadAction"> 
			<result name="success" type="stream"> 
				<param name="contentType">application/octet-stream</param> 
				<param name="inputName">inputStream</param> 
				<param name="contentDisposition">attachment;filename="${downloadFileName}"</param> 
				<param name="bufferSize">4096</param> 
			</result> 
		</action> 

这时需要把fileName作为参数传过来.
以下是action.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import com.opensymphony.xwork.Action;

public class FileDownloadAction implements Action {
	
	private String fileName = "";
	
	public InputStream getInputStream () throws Exception {
		InputStream is = null;
		try {
			is = new FileInputStream(fileName);
		} catch (FileNotFoundException e1) {
		}
		return is;
	}
	
	public String execute () throws Exception {
		return SUCCESS;
	}
	
	public void setFileName (String fileName) {
		this.fileName = fileName;
	}
	
	public String getFileName () {
		return fileName;
    }

	public String getDownloadFileName () {
		String downFileName = fileName;
		try {
			downFileName = new String(downFileName.getBytes(), "utf8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return downFileName;
	}
}
分享到:
评论
2 楼 hbing110 2010-10-20  
对不起  没有  我当时只是在ie7下做的开发。
1 楼 xrqsjj 2010-10-18  
有没测试在IE6下进行下载

相关推荐

Global site tag (gtag.js) - Google Analytics