When uploading files smaller than 5MB that trigger a server-side exception, the server correctly responds with a 500 Internal Server Error, as expected.
However, for files larger than 5MB that also trigger an exception, instead of a 500 error, the client receives a net::ERR_CONNECTION_RESET error.
This inconsistency in behavior for different file sizes is puzzling, especially since the maxPostSize setting should theoretically allow for files of any size, and I would expect the server to consistently return a 500 error for all exceptions.
upload.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Upload Example</title>
</head>
<body>
<h2>File Upload to JSP</h2>
<input type="file" id="fileInput" name="file">
<button onclick="uploadFile()">Upload File</button>
<script>
function uploadFile() {
var fileInput = document.getElementById('fileInput');
var file = fileInput.files[0];
var formData = new FormData();
formData.append('file', file);
const xhr = new XMLHttpRequest();
xhr.open('POST', './upload1.jsp', true);
xhr.addEventListener('load', function () {
console.log('done', xhr.responseText);
});
xhr.upload.addEventListener('progress', function (e) {
console.log('progress', e.loaded, e.total);
});
xhr.addEventListener('error', function (e) {
console.log('error', e);
});
xhr.onreadystatechange = function () {
console.log(xhr.readyState, xhr.status)
}
xhr.send(formData);
}
</script>
</body>
</html>
upload1.jsp
<%@page contentType="text/html;charset=utf-8" %>
<%
try{
int a = 10/0; // 서버 측 예외 상황 시뮬레이션
}catch(Exception e){
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
}
%>
Using tomcat 8.5, and configuring maxPostSize to -1 in Tomcat to allow unlimited file sizes