简体   繁体   English

尝试将文件上传到tomcat服务器时,连接不断重置

[英]Connection keeps getting reset when trying to upload file to tomcat server

I am trying to create a website where people can post stuff. 我正在尝试创建一个人们可以在其中发布内容的网站。 Currently, I am trying to make it such that users can add files sequentially and send it as a multi-part request in ajax.However, I keep getting connection reset error in chrome when I am trying to upload files. 目前,我正在尝试使用户可以依次添加文件并将其作为多部分请求发送到ajax中。 I have to log back into the server in order to see the new files. 我必须重新登录服务器才能查看新文件。

HTML code: HTML代码:

<form id="postForm" method="post" enctype="multipart/form-data">
                        <textarea name="text" rows="4" cols="" class="form-control" placeholder="What's Up" id="postTextarea"></textarea>
                        <div class="radio">
                            <label><input type="radio" name="privacy" value="restricted" checked>Restricted</label>
                            <label class="checkbox-inline"><input type="checkbox" name="group" value="family" class="group">Family</label>
                            <label class="checkbox-inline"><input type="checkbox" name="group" value="bestie" class="group">Besties</label>
                            <label class="checkbox-inline"><input type="checkbox" name="group" value="friend" class="group">Friends</label>
                        </div>
                        <div class="radio">
                            <label><input type="radio" name="privacy" value="public">Public</label>
                        </div>
                        <br>
                        <div id="fileContainer">

                        </div>
                        <div id="buttonContainer">
                            <label class="btn btn-default" id="fileUploadButton">
                                Add Files<input type="file" name="file" class="fileInput" hidden multiple>
                            </label>
                            <button class="btn btn-primary" id="postButton">Post</button>
                        </div>
                    </form>

JavaScript: JavaScript:

var submittedFileData = [] ;
$('.fileInput').on('change', function () {
        var files = $(this).prop('files') ;
        for (var i = 0; i < files.length; i++) {
            var p = document.createElement("p") ;
            $(p).text(files[i].name + " (Click here to remove file)") ;
            $(p).addClass("filename") ;
            $("#fileContainer").append(p) ;
            submittedFileData.push(files[i]);
        }
    });
$('#postButton').click(function () {
        var privacy = $( "input[type=radio][name=privacy]:checked" ).val();
        var formData = new FormData();
        //append privacy
        formData.append("privacy" , privacy) ;
        //append groups
        $( "input[type=checkbox][name=group]:checked" ).each(function(i) {
            formData.append("group" , $(this).val()) ;
        }) ;
        //append text
        formData.append("text" , $("#postTextarea").val()) ;
        //append files
        for (var i = 0; i < submittedFileData.length; i++) {
            formData.append("file" , submittedFileData[i]) ;
        }
        $.ajax({
            type: "POST",
            url: "post-upload",
            data: formData,
            processData: false,
            contentType: false,
            cache: false,
            async : false,
            success: function (data) {
            },
            error: function (jqXHR, textStatus, errorThrown) {
               alert(errorThrown) ;
            }
        });
        $.post("feed-view","relation="+activeTab ,getXMLResponse) ;
    });

server.xml for tomcat 9 Tomcat 9的server.xml

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImplementation"
           maxThreads="150" SSLEnabled="true"
            scheme="https"
       secure="true" maxPostSize="-1" disableUploadTimeout="false" connectionUploadTimeout="600000">
    <SSLHostConfig>
        <Certificate certificateKeystoreFile="C:/Users/Kathavarayan/.keystore"
            certificateKeystorePassword=""
                     type="RSA" />
    </SSLHostConfig>
</Connector>

It's very likely that there isn't anything code-wise that is wrong, but instead it is a server configuration issue. 很有可能没有任何代码错误,但这是服务器配置问题。

By default, most servers are set to both rather small timeouts and rather small upload size limits. 默认情况下,大多数服务器都设置为较小的超时和较小的上传大小限制。

It depends on what type of server you are using (nginx, Apache, Node/Express, etc) for what the defaults are and how to configure them, but that would be the first thing I look into if your connection is resetting or cutting off mid-upload. 这取决于您使用的服务器类型(nginx,Apache,Node / Express等)的默认设置以及如何配置它们,但这是我首先要研究的问题,如果您的连接正在重置或中断中载。

I finally discovered the problem. 我终于发现了问题。 You are probably not going to believe this but at the end of the day, the button in the form was still causing it to be submitted causing the entire process to mess up. 您可能不会相信这一点,但是在一天结束时,表单中的按钮仍然导致它被提交,从而导致整个过程混乱。 All I had to do was add type="button" to the button element in the form. 我要做的就是将type =“ button”添加到表单中的button元素。 Now, this prevents the form from being submitted and only causes Ajax to take care of submitting the form. 现在,这阻止了表单的提交,仅使Ajax负责提交表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ajax将文件上传到服务器上传目录。 图片未上传到上传目录; 收到连接重置错误 - File upload to server upload directory by using ajax. The image is not getting uploading to upload directory; getting the error of connection reset 尝试使用 Node 将图像上传到 S3 时,为什么会出现此连接错误? - Why am I getting this connection error when trying to upload an image to S3 with Node? 使用 multer 上传文件时 Node.js 连接重置 - Node.js connection reset on file upload with multer 在端口 8080 上使用 Webpack 开发服务器获取 ERR_CONNECTION_RESET - Getting an ERR_CONNECTION_RESET with Webpack Dev Server on port 8080 尝试上载到存储时出现firebase错误 - Getting firebase error when trying to upload to storage 文件上传重置数组 - Reset array for file upload 在AngularJS中重置文件上传 - File Upload reset in AngularJS 尝试将文件上传到Google驱动器api时收到404,怀疑是数据格式问题 - getting a 404 when trying to upload a file to the google drive api, suspecting a data formatting issue 尝试将文件上传到 s3 时出现“不支持的正文有效负载对象”错误 - Getting "Unsupported Body Payload Object" error when trying to upload file to s3 尝试在 React 组件中的表单中上传 PDF 文件,但是当我使用 setFormData 时得到 {} - Trying to upload a PDF file in my form in React component but getting {} when I use setFormData
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM