日期:2014-05-17  浏览次数:20788 次

一个word文档从服务器下载到本地的问题,怎样弹出保存提示框?
各位,请教:

程序生成一个excel存在服务器一个目录中,环境是weblogic+linux做的,现在需要下载这个xls文件,路径是对的,比如 http://127.0.0.1:8080/file/20130821.xls,现在想要把它写在一个a标签里面,用户一点击,就弹出保存的对话框,如果是XP系统就问你:打开  保存  取消,如果是win7就如图这样:
就是系统带的这样保存的功能。

但是,现在遇到的问题是,浏览器不提示保存,是在浏览器里打开了,而且是乱码(我怀疑是weblogic的原因)。目标另存为的话文件的格式是html的,修改成xls可以正常显示。

现在想请教大家,服务器上的xls文件需要下载到本地,有什么好的招?

谢谢
excel下载 word下载 目标另存为

------解决方案--------------------
另存为的时候 不可以选择别的格式吗?
------解决方案--------------------
是什么浏览器?一般浏览器里有设置的地方。可能是设置为默认保存了
------解决方案--------------------
代码:
/**
 * 下载管理器
 * @description
 */
public class DownLoadAction extends BaseAction {
private static final long serialVersionUID = 1L;
private String fileName = null;
private InputStream  tempStream = null;
private byte[] bytes = null;
private String filePath = null; //文件地址
private Integer id=null;
@Resource
private IAnnexService annexService=null;

/**
 *  查看附件
 * @return
 */
public InputStream getInputStream() throws Exception {
Annex annex=annexService.find(Annex.class, id);
File file = new File(getFileBasePath() + annex.getUrl());
File file2=new File(getFileBasePath() + File.separator+"download"+File.separator+DecoderUtil.UtfDecoder(annex.getName()));
file2.getParentFile().mkdir();
FileUtil.copyFile(file, file2);
try {
this.setFileName(new String(file2.getName().getBytes(), "ISO8859-1"));
tempStream = new java.io.FileInputStream(file2);//从系统磁盘文件读取数据
bytes = new byte[tempStream.available()];
if(tempStream != null) {
tempStream.read(bytes);
}
tempStream.close();
return new ByteArrayInputStream(bytes);