美文网首页CodingStudying
练习-uploadFile记录

练习-uploadFile记录

作者: 7ack | 来源:发表于2016-10-24 13:15 被阅读15次

    上传文件报错

    [ERROR]file upload error.
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    

    报错的代码 officeUtil.java

    String htmlPath = filePath.substring(0,filePath.lastIndexOf("/"))+"/html";
    
    • 发现diskFile的路径是C:\app\ftp\announcement\2016\10\14\9674574120311.xls
      所以找不到"/",于是改成
    String htmlPath = filePath.substring(0,filePath.lastIndexOf("\\"))+"\\html";
    

    不报错,但是涉及到了路径的更改,感觉windows的路径和其他系统的不一样,可能会影响其他平台的使用?

    • 2016年10月18日更新
    1. 将property的path全部改成c:/
    2. 因为windows也可访问/的路径 除了 String htmlPath = filePath.substring(0,filePath.lastIndexOf("\\"))+"\\html";其他全部改成/
    3. 上传图片无法显示预览
    • 上传图片直接调用FileUploadController的uploadPic,改写了方法,加上了对type的判断使其使用于公告图片的上传,但是上传后无法显示预览图片,查看页面:<img id="pic" src="C:/app/ftp/images/announcement/image/2016/10/18/1476778297615.jpg" width="160" height="80">发现是图片的路径错误,name前面少了一个/,于是改写FileUploadController.uploadPic,在fileName前加上一个/

      3.1 依然无法显示

      • 仔细观察发现,图片的路径是C:/app/ftp/images,查看本地发现么有这个路径,原来这是配置文件中的imgPath.但是这个path的路径是C:/app/ftp/images/后面多了一个/,索性改成了C:/app/ftp/但是然并软..查看web发现直接点击链接是可以查看本地文件的.但是编辑框里就是不能显示,显示错误Not allowed to load local resource: file:///C:/app/ftp/announcement/image/2016/10/18/1476781179860.jpg!最后发现是由于chrome处于安全考虑不能加载绝对路径的本地文件..呵呵
      • 2016年10月20日更新
        搭建本地http服务器,可以加载!
        3.2 上传删除再上传图片预览么有更新
      • 增加重载上传图片的div 使用html()

    连接本地的openOffice服务错误

    connection failed: socket,host=localhost,port=8100,tcpNoDelay=1
    

    查看报错的文件

    Source not found
    The JAR file C:\.....\jodconveter-2.2.2.jar has no source attachment.
    
    • 查看路径,发现maven的jodconveter下么有source包,于是从网上下载,手动添加后解决

    获取OpenOffice连接失败

    connection failed: socket,host=localhost,port=8100,tcpNoDelay=1
    
    • 很明显是openOffice的服务么有开启,于是网上下载了openOffice
      进入安装目录C:\Program Files (x86)\OpenOffice 4\program shift 右键 打开命令行
      输入
    soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 
    
    • 打开服务后,可以进行转换,但是插入数据库的html路径是windos下的绝对路径,待解决
    • 但是每次都要手动打开服务有点麻烦,试着在代码中加入打开服务以及关闭服务
             String command =  "C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard ";  
             Process pro = Runtime.getRuntime().exec(command);  
    
            // 创建Openoffice连接
            OpenOfficeConnection con = new SocketOpenOfficeConnection(8100);
            try {
                // 连接
                con.connect();
            } catch (ConnectException e) {
                logger.error("获取OpenOffice连接失败...",e);
            }
            // 创建转换器
            DocumentConverter converter = new OpenOfficeDocumentConverter(con);
            // 转换文档问html
            converter.convert(docFile, htmlFile);
            // 关闭openoffice连接
            con.disconnect();
            //关闭openOffice服务
            pro.destroy();
    
    • 运行代码后,上传成功
    update pic_info SET business_type = 201, pic_url = '/announcement/2016/10/15/3329715835213.xls', 
    file_type = 'xls', real_name = 'xx工作周报.xls', html_path = 'C:\app\ftp\announcement\2016\10\15\html\3332052044145.html' 
    where id = 613311
    
    • 成功!
    • 2016年10月18日更新
    1. 将openOffice的command加在了property文件中,便于修改.
    2. 解决了openOffice转码html后乱码的问题:更改openOffice配置,将字符格式设置为utf-8,将输出设置为html3.2

    404错误

    警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:vj-practice-manager' did not find a matching property.

    The solution to this problem is very simple. Double click on your tomcat server. It will open the server configuration. Under server options check ‘Publish module contents to separate XML files’ checkbox. Restart your server. This time your page will come without any issues.

    完成上传后,点击编辑,显示loading动画后卡死

    • 未解决?????
    • 原因是create的时候么有添加可见部门等数据的操作,导致加载的时候无法读取相关的list导致一直卡死

    相关文章

      网友评论

        本文标题:练习-uploadFile记录

        本文链接:https://www.haomeiwen.com/subject/qylluttx.html