File upload
A more efficient and simple upload method has evolved in Java EE 7. Now, we can upload files through our web forms with little code. In this section, we will see a very practical sample. Now, let's start creating an upload form through a JSP page:
<form action="${pageContext.request.contextPath}/FileUploadServlet"method="post" enctype="multipart/form-data"> <input type="file" name="file" size="50" /> <br /> <inputtype="submit" value="Upload File" /> </form>
With this code, we can upload files on a chosen platform. The web form allows us to interact with a server. In this case, we can attach a file through the input file tag. To send the file to the server, we need to configure the form with a particular enc
type, the multipart/form-data
. It is the standard mode used to send the files. Here's a list of the available enc
types of the forms:
Value | Description |
application/x-www-form-urlencoded | Default; all characters are encoded before they are sent... |