在点击url超链接下载文件时,第一次会报找不到需要的内容HTTP/1.0 404错误

soarsoar77 2012-09-29 05:08:15

我开发了可以下载文件的页面,但在第一次点击或者刷新后第一次点击,都会报找不到需要的内容(HTTP/1.0 404)错误,再点又可以下载文件,这是什么原因?是服务器的问题还是客户端IE的设置问题?

有谁有解决办法的,帮个忙啊,谢了!
...全文
1106 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Giberson1 2012-10-09
  • 打赏
  • 举报
回复
如果你觉得是IE设置的问题,你可以用别人的电脑试下,这样就可以排除你的猜想。
soarsoar77 2012-10-09
  • 打赏
  • 举报
回复
没有人回答下吗?
soarsoar77 2012-10-03
  • 打赏
  • 举报
回复
再顶一次,希望有人看到回答下
soarsoar77 2012-10-02
  • 打赏
  • 举报
回复
这是什么原因,哪位大神帮帮忙,挺着急的。。。
soarsoar77 2012-10-02
  • 打赏
  • 举报
回复
public class DownFileAction extends Action{
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

Collection<ERRBean> colerr = new ArrayList<ERRBean>();

request.setCharacterEncoding("GB2312");

String filename = request.getParameter("fname");
System.out.print("filename:" + filename);
//从配置文件中读取格式文件路径
Configuration config1 = new Configuration("config/fkll.properties");
String SystemType = config1.getValue("SysType");
String fPath =null;
if (SystemType.equals("1"))
{
fPath = config1.getValue("FileC1");
}

if (SystemType.equals("2"))
{
fPath = config1.getValue("FileC2");
}

if (SystemType.equals("3"))
{
fPath = config1.getValue("FileC3");
}
String filepathname =fPath + filename.trim();
System.out.print("filepathname:" + filepathname);

File f =new File(filepathname);
if (!f.exists())
{
ERRBean tmpErr = new ERRBean();
tmpErr.setErrNR("文件不存在,无法下载!");
tmpErr.setErrPage("main_FileList.jsp");
tmpErr.setErrBZ("错误");
colerr.add(tmpErr);
request.getSession().setAttribute("colerr", colerr);
return mapping.findForward("failure");
}

byte[] b = null;


try {
String snm_path;

snm_path = filepathname;
FileInputStream aa = new FileInputStream(snm_path);
b = new byte[aa.available()];
aa.read(b);
aa.close();
// 将文件信息取回到页面中
response.setContentType("application/x-msdownload;charset=GBK");
String s = " attachment;filename=" + new String(filename.getBytes("GBK"), "ISO8859_1"); //
response.setHeader("Content-Disposition", s); // 以上输出文件元信息
response.setContentLength(b.length);
response.getOutputStream().write(b, 0, b.length);
response.getOutputStream().close();

} catch (IOException e) {
System.out.println("下载文件失败: " + e.getMessage());
}
return null;
}
}


这个是我完整的下载文件代码,我的下载是做在Excel的超链接里的,也就是把Excel单元格的超链接设置成我服务器的网址 + ?fname= + 实际要下载的文件名称,这样点击Excel单元格就能下载需要的文件了,但第一次点击总是下载不成功,再次点击就能下载成功了。
  • 打赏
  • 举报
回复
这是你代码的问题,代码弄上来看看啊
soarsoar77 2012-09-29
  • 打赏
  • 举报
回复
没人碰到这种问题么?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧