-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
In your HTML form, you just need a form with a file input and a submit button:
<form method="post" action="path/to/servlet" enctype="multipart/form-data">
<input type="file" required name="file"/>
<input type="submit" />
</form>Minimal HTML for single file upload.
In the server-side using Servlet 3.0 API, some simple code are needed:
@MultipartConfig(location = "path/to/file/directory", fileSizeThreshold = maxSizeOfFileOnDisk)
@WebServlet("/path/to/servlet")
public class FileServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Part file = req.getPart("file");
if (file != null) {
file.write(name);
}
}
}This is the minimal required code for this to work.