- Java code
package com.company.action;import java.io.InputStream;import java.io.UnsupportedEncodingException;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;import com.opensymphony.xwork2.Action;@Results( { @Result(name = "success", type = "stream", params = { "contentType", "application/x-msdownload", "inputName", "inputStream", "contentDisposition", "attachment;filename=%{url}", "bufferSize", "5120" }) })public class DownAction implements Action { // 文件地址 private String url; public InputStream getInputStream() throws Exception { InputStream inputStream = ServletActionContext.getServletContext() .getResourceAsStream(url); return inputStream; } /**** * 默认执行下载文件 */ public String execute() throws Exception { return SUCCESS; } public String getUrl() { return url; } public void setUrl(String url) { // 进行中文转码 try { url = new String(ServletActionContext.getRequest().getParameter( "url").getBytes("iso-8859-1"), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } this.url = url; }}
上面这段代码在Ie8下能正常下载 迅雷快车也可以 但是在用ie6文件另存为的时候下载下来的文件都是未知的 都是down名的未知文件请问我哪里写错了!
------解决方案--------------------
up
没见过
------解决方案--------------------
LZ设置contentType试试。
我也没用struts2下载过文件
------解决方案--------------------
求一个小项目源代码,最好struts+jdbc+mysql+jsp 最好有增删改等功能! 谢谢各位啦!lql20121201@163.com 急用!谢啦~