菜鸟女玩家 2020-07-09 16:43 采纳率: 100%
浏览 255
已采纳

struts+layui中富文本图片上传接口怎么写?

使用ssi框架+layui写的项目,其中用到了layui的富文本,图片上传接口怎么也写不出来,各位神仙请帮帮我

js:

layer = layui.layer;
table = layui.table;
 var layedit = layui.layedit;
 layedit.set({
        uploadImage: {
            url: ctx + '/jszjh/jszjhfbgl!srcUrl.do?' //接口url
            ,type: 'post' //默认post
        }
    });
 var layidx = layedit.build('wznr',{
        height: 700}); //建立编辑器

jsp:

<textarea id="wznr" name="wznr" style="display: none;"></textarea>

后台Action不知道怎么写

  • 写回答

2条回答 默认 最新

  • donghui108 2020-07-14 16:55
    关注

    拿走不谢
    public String srcUrl(){
    Map map = new HashMap();
    Map mapSrc = new HashMap();
    map.put("code", 1); //0表示上传成功
    map.put("msg","上传失败"); //提示消息
    mapSrc.put("src", "");
    mapSrc.put("title", "");
    map.put("data", mapSrc);
    String rootPath = request.getSession().getServletContext().getContextPath();//根目录
    try{
    if(file==null){
    responseJson(map);
    return null;
    }
    long maxSize = (1024 * 1024) * 10;
    long fileSize = file.length();
    String size = this.getFileSize(fileSize);
    if (fileSize > maxSize) {
    map.put("msg","上传失败,资源信息最大上传10MB,当前文件" + size + "!"); //提示消息
    responseJson(map);
    return null;
    }

       String path="C:\\Users\\ASUS\\Desktop\\jszjh";
    

    // String path=Constants.JSZJHFBGLPATH;

       File p = new File(path);
       if(!p.exists()) p.mkdirs();
       String nbwjm = parseWjFile(file, fileFileName,path);
    
       map.put("code", 0); //0表示上传成功
             map.put("msg","上传成功"); //提示消息
             mapSrc.put("src", rootPath+"/province/other/jszjh/jsp/pcCreate.jsp?pth="+path+ File.separator + nbwjm);
             mapSrc.put("title", nbwjm);
             map.put("data", mapSrc);
             responseJson(map);
       return null;
      }catch(Exception x){
       responseJson(map);
       return null;
      }
     }
     // 获取文件大小
     public String getFileSize(long fileLength) {
      String size = "0";
      double len = fileLength;
      DecimalFormat df = new DecimalFormat("0.0");
      if (len > 0.1 * 1024 * 1024) {
       size = df.format(len / (1024 * 1024)) + "MB";
      } else if (len > 0.1 * 1024) {
       size = df.format(len / 1024) + "KB";
      } else {
       size = len + "B";
      }
    
      return size;
     }
     /**
      * 复制文件
      */
     public String parseWjFile(File file, String wjmc, String filePath) {
      // 新文件
      File dir = new File(filePath);
      if (!dir.exists()) {
       dir.mkdirs();
      }
      String wjid = System.currentTimeMillis() + wjmc;
      File uploadCopyWord = new File(filePath + File.separator + wjid);
      FileUtil.copyFile(file, uploadCopyWord);
        return wjid;
    }
    
    
    
    
    
    
    
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献