extjs中submit提交后不进入success也不进入failure 解决方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Pnoter/article/details/51894776

首先说明是后台返回的json返回值格式不对

要执行successfailure,需在返回的json中有如下字段 :

执行success里面的操作
{success:true}

执行failure里面的操作
{success:false}

首先要确定你Extjs上传文件代码正确性(提供部分代码)

buttons : [ {
            text : '上传文件',
            handler : function() {
                var form = this.up('form').getForm();
                var fileName = Ext.getCmp("fileid").getValue();
                fileName = fileName.split('.');
                fileName = fileName[fileName.length - 1];
                if (fileName != "doc" && fileName != "docx") {
                    Ext.Msg.alert("系统提示", "必须选择Microsoft Office Word 文档!");
                    return false;
                }
                if (form.isValid()) {
                    form.submit({
                        method : 'post',
                        url : 'announce/upFile.do',
                        waitMsg : '文件上传中,请稍等...',
                        success : function(fp, o) {
                            Ext.Msg.alert('成功', '上传成功!');
                        }
                    });
                }
            }
        } ]

后台Java返回代码

特别提醒:response.getWriter().print("{success:true}");
返回字符串的格式为:{success:true}或{success:false}

/* 附件上传 */
    @RequestMapping("/upFile")
    public @ResponseBody void upFile(HttpServletRequest request, HttpServletResponse response,
            @RequestParam("file") CommonsMultipartFile file) throws IOException {
        /* 获取项目工程的实际目录,并且在该真实路径下创建一个uploadFiles目录 */
        String filePath = request.getSession().getServletContext().getRealPath("/uploadFiles/");
        /* 获取文件名 */
        String fileName = file.getOriginalFilename();
        /* 获取文件的后缀,通过后缀可分辨文件的类型 */
        String fileType = fileName.split("[.]")[1];
        /* 为了避免文件名重复,在文件名前加UUID */
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(2, 10);
        String uuidFileName = uuid + fileName;
        /* 文件上传 */
        FileUtil.upFile(file.getInputStream(), uuidFileName, filePath);
        response.getWriter().print("{success:true}");
    }

猜你喜欢

转载自blog.csdn.net/Pnoter/article/details/51894776