I have a servlet and want to restrict uploaded files using the maxFileSize
parameter. After some acts I want to send response to my page. It all works with another errors (not maxFileSize
).
If the file is big, I get on my page this error:
ERR_CONNECTION_RESET
(but it's not controlled by me). And I can't get adequate text.
In Java when I do String param = req.getParameter("param");
I get the error
java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field fileList[] exceeds its maximum permitted size of 10485760 bytes.
There is an old issue with the same problem org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException
Java:
@WebServlet(urlPatterns = "/my_page")
@MultipartConfig(
fileSizeThreshold = 1*1024*1024,
maxFileSize = 10*1024*1024,
maxRequestSize = 50*1024*1024)
public class MyServlet extends HttpServlet {
...
String param = req.getParameter("param");
...
req.setAttribute("infoResult", "File is too big");
req.getRequestDispatcher("my_page.jsp").forward(req, resp);
Javascript:
const xhr = new XMLHttpRequest();
xhr.open("POST", "${pageContext.request.contextPath}", true);
xhr.timeout = 10000;
xhr.send(formData);
xhr.onerror = function () {
// I get xhr.status = 0 here and nothing in responseText
};
xhr.onreadystatechange = function () {
// I get xhr.status = 0 here and nothing in responseText
};