Java servlets using MultipartConfig

I use catch-all servlet and pass the request object along with other internal infrastructure classes. Its a way to develop my application. Reasons are beyond the scope of this issue.

@WebServlet(name="RequestHandler", urlPatterns="/*")

I am trying to download files from a browser using multipart-form-data:

<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="file"/>
    <input type="submit" name="videoUpload" value="Upload"/>
</form>

And the only way to transfer file data with the server is to annotate the servlet with:

@MultipartConfig

If I annotate my servlet-catch-all, everything works fine, but not very often, that I really need to use the file upload function.

Option 1: Leave him alone. Do annotations leave unnecessary overhead, even if most queries don't use it?

2: ? , multipart?

3: . ( , ...)?

+4
1

, '@MultipartConfig'. , :

 String form_field="";
 FileItem fileItem = null; 
 if (ServletFileUpload.isMultipartContent(request)) {
            ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
            try {
                fileItemsList = servletFileUpload.parseRequest(request);
            } catch (FileUploadException ex) {
                out.print(ex);
            }
            String optionalFileName = "";
            Iterator it = fileItemsList.iterator();
            while (it.hasNext()) {
                FileItem fileItemTemp = (FileItem) it.next();
                if (fileItemTemp.isFormField()) {
                    if (fileItemTemp.getFieldName().equals("form_field")) {
                        form_field = fileItemTemp.getString();
                    }
                } else {
                    if (fileItemTemp.getFieldName().equals("file")) {
                        fileItem = fileItemTemp;
                    }
                }
            }
        }

ServletFileUpload.isMultipartContent() , request.getParameter. apache .

+1

All Articles