诶诶诶略 2016-05-13 06:20 采纳率: 0%
浏览 1741

easyui信息修改时,重新上传图片,旁边显示新的图片

图片说明
图片说明
图片说明
上传成功后显示现在上传的图片

  • 写回答

2条回答 默认 最新

  • 时间的殇 2016-05-13 08:54
    关注

    /**
    * 下载方法(在页面上显示不保存在该项目里的图片)
    * @param mapping
    * @param ctrlForm
    * @param request
    * @param response
    * @return
    * @throws Exception
    */
    public void showImg(ActionMapping mapping, ActionForm ctrlForm,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    Properties Prop = new Properties();
    InputStream Input = SysHelpBiz.class.getResourceAsStream("FilePath.properties");
    Prop.load(Input);
    String sd_path = Prop.getProperty("PATH");
    File file = new File(sd_path+File.separator+request.getParameter("path"));
    String filename = file.getName();
    response.setContentType("application/x-msdownload; charset=utf-8");
    response.setContentLength((int) file.length());
    response.setHeader("Content-Disposition", "attachment;filename="
    + java.net.URLEncoder.encode(filename, "UTF-8"));
    // read file
    FileInputStream fis = null;
    OutputStream myout = null;
    try {
    fis = new FileInputStream(file);
    BufferedInputStream buff = new BufferedInputStream(fis);
    byte[] b = new byte[1024];
    long k = 0;

            myout = response.getOutputStream();
            while (k < file.length())
            {
                int j = buff.read(b, 0, 1024);
                k += j;
                myout.write(b, 0, j);
            }
            myout.flush();
        } catch (Exception e) {
            throw  new RuntimeException("文件下载时出现异常");
        } finally {
            fis.close();
            myout.close();
        }
    }
    
    页面
    <img src='<%=path%>/cjsc.do?method=showImg&path=${p.BMUS_PIC}' width="60px" height="50px"/>
    这里的path只是个图片名
    
    仅供参考。
    
    评论

报告相同问题?

悬赏问题

  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题