页面上肯定不能用file:///C:/123.png这样的路劲的。

解决方案 »

  1.   


    额,因为我数据库里面存放的是    
    C:/123.png c:/123.doc 这样的地址呢,
    我给<img >的src 赋值 C:/123.png 的时候 为什么也不能直接显示图片呢,谢谢。我那不是直接使用,我是点右键查看,看到的是那个地址,我实际上使用的是数据库中存放的
    C:/123.png 这样的地址啊。
    以前用Struts2的时候是可以直接这样取地址的啊,谢谢。
      

  2.   

    前端使用window.location.href=url或者window.open(url),url表示请求路径,浏览器即可弹出下载窗口(前提是你给的的url返回的是文件或者stream)。
      

  3.   

    谢谢,这样确实可以,不过为嘛我用AJAX提交就是不行呢?谢谢,还有,如果文件是图片的话,我只想预览,不想下载,
    为什么(我用JQUERY的方式操作的)。设置IMG标签的SRC属性为数据库中的物理地址的时候不起作用呢?右键查看的时候,貌似把路径中的斜杠给去掉了,这是为嘛啊?
      

  4.   

    jQuery的ajax函数、及ajaxSubmit等函数的返回类型(dataType)只有xml、text、json、html等类型,没有“流”类型.所以你只能这样写个请求:
    window.location.href = path+'/phoneInfo/downloadTemplate.do';
      

  5.   

    基于springMVC+springSecurity3.x+Mybaits3.x的权限系统,,开放源码,支持开源
    具体请看:
    http://blog.csdn.net/mmm333zzz/article/details/16863543
      

  6.   

    response.setContentType("multipart/form-data");
    最好写MimeType属性,如果要浏览器在线开必须这么做;
    multipart/form-data用于二进制六下载使用
      

  7.   

    图片src必须写浏览器可达地址,也就是你的下载的URL地址,不要写服务器文件地址,访问不到的
      

  8.   

    项目处于某种安全考虑,木有放到项目下面。而是放到了Tomcat的tmp目录下面。
      

  9.   

    图片src必须写浏览器可达地址,也就是你的下载的URL地址,不要写服务器文件地址,访问不到的恩,我到tomcat的server.xml配置文件中配置了一个虚拟映射路劲之后就可以访问了,不过访问中文的图片还是会报错。
      

  10.   

    src写你上面代码中的控制器地址,直接输出到response
      

  11.   

    恩,这个是前端穿了个id过来,然后我从word中将图片读出来,根据id,返回具体的那张图片给页面展示@RequestMapping("/image")
        @ResponseBody
        public String getImagePath(HttpServletRequest request,HttpServletResponse response) {
    String filePath = null;
    try {
    filePath = new String((request.getParameter("filePath")).getBytes("iso-8859-1"),"utf-8");
    } catch (UnsupportedEncodingException e1) {
    e1.printStackTrace();
    return null;
    }

    String idx = request.getParameter("id");
    if (filePath == null || idx == null) {
    return null;
    }

    response.setContentType("image/jpeg");
    int index = Integer.parseInt(idx);
    try {
    ServletOutputStream out = response.getOutputStream();
    WordDocUtil wdu = new WordDocUtil(filePath);
    List<byte[]> imageCache = wdu.getAllDocPicture();
    if (imageCache != null && index < imageCache.size()){
    out.write(imageCache.get(index));
    }
    out.flush();
    wdu.closeStream();
    } catch (IOException e) {
    e.printStackTrace();
    }
    return null;

    }
      

  12.   

    response.sendRedirect("这里传资源的url");//url可以是资源的相对路径
    return null;
    这样就把文件流传到前台了,页面自然会弹出下载框
      

  13.   

    response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
    response.setContentType("application/x-msdownload;charset=utf-8");
    response.flushBuffer();试试这个
      

  14.   

    1. jQuery的ajax的返回类型(dataType)只有xml、text、json、html等类型,没有“流”类型.
    window.location.href = download.do
    通过这个地址来下载。2. 图片的话,因为你没放在项目的路径下,
    所以你需要到tomcat的server.xml配置文件中配置一个虚拟映射路径
    在host 下<context> 配置一个就可以了。