无法通过https上的servlet调用上传大于7KB的文件

时间:2017-11-08 13:58:13

标签: ajax jsp servlets jboss

我正在运行 JBoss 6.3门户并部署了包含以下两个文件的war文件

1) DocUpload.jsp

包含以下代码段进行ajax调用,以便在 data2 中发送上述字段以及文件对象 fd

fd.append('file', document.getElementById('file1').files[0]);

data2 = encodeURIComponent(document.getElementById("lob").value)+'@'+encodeURIComponent(document.getElementById("loantype").value)+
            '@'+encodeURIComponent(document.getElementById('docType').value)+'@'+encodeURIComponent(document.getElementById('docName').value)+
            '@'+encodeURIComponent(document.getElementById('entity').value)+'@'+encodeURIComponent(document.getElementById('userName').value)+
            '@'+encodeURIComponent(document.getElementById('PartyName').value)+'@'+encodeURIComponent(document.getElementById('loanAccount').value)+
            '@'+encodeURIComponent(document.getElementById('LoanAmount').value)+'@'+encodeURIComponent(e4)+'@'+encodeURIComponent(document.getElementById('hiddenWIName').value)+'@'+encodeURIComponent(e3);
alert("data2 "+data2);
var ret = doPostAjax("${pageContext.request.contextPath}/AddDocumentsServlet?data="+data2,fd);

2) AddDocumentsServlet.java

包含处理请求的代码

            File path = new File(RootFolderPath + File.separator + "Portal_TmpDoc" + File.separator + todayAsString + File.separator + lMilliSecondsCurrent);
            UploadPath = path.getAbsolutePath();
            if (!path.isDirectory()) {
                path.mkdirs();
            }
            if (isMultipart) {
                System.out.println("Inside if isMultipart");

                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(MEMORY_THRESHOLD);
                factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setFileSizeMax(MAX_FILE_SIZE);
                upload.setSizeMax(MAX_REQUEST_SIZE);
                try {
                    //List multiparts = upload.parseRequest(request);
                    System.out.println("Before parsing request");
                    List<FileItem> multiparts = upload.parseRequest(request);
                    System.out.println("multiparts :::"+multiparts);
                    for (Iterator iterator = multiparts.iterator(); iterator.hasNext();) {
                        FileItem item = (FileItem) iterator.next();
                        logger.info(item);
                        if (!item.isFormField()) {

                            String fileobject = item.getFieldName();
                            System.out.println(request.getParameter("data"));
                            String[] fileArray = request.getParameter("data").split("@");

                            name = new File(item.getName()).getName();
                            name = name.substring(name.lastIndexOf(File.separatorChar) + 1);
                            ext = name.substring(name.lastIndexOf(".") + 1);
                            logger.info(name);
                            File directory = new File(UploadPath);
                            File[] afile;
                            int j = (afile = directory.listFiles()).length;
                            for (int i = 0; i < j; i++) {
                                File f = afile[i];
                                if (f.getName().startsWith(filename))
                                    f.delete();
                            }
                            item.write(new File(UploadPath + File.separator + filename + "." + ext));
                            System.out.println("File Uploaded");
                        }
                    }

我的问题是,当我使用http连接进行上述请求并获得会话时程序运行正常。但是,当使用https并上传大于7 KB的文件时,页面将无法响应。

在进一步分析中,我发现程序流程停留在此行

List<FileItem> multiparts = upload.parseRequest(request);

尽管在try块中有这一行,但没有异常被捕获。

0 个答案:

没有答案